Different markers for same data set in gnuplot - gnuplot

I have a dataset consisting of two columns in a file. Is it possible to have different markers for each data point when plotting them?
I know I could do this by doing a BASH for loop generating a string of plot commands, but I was wondering if there is any way of doing it directly in gnuplot?
I was thinking something like marker type 1 for first data point, marker type 2 for the second data point, and so on.

To change the linecolor or the point size based on a column's value (or the row number), gnuplot knows the linecolor variable and pointsize variable parameters. However, that doesn't work for pointtype.
Gnuplot itself has some kinds of iteration loops. You would need to count your rows with stats and then iterate over each row using the loop variable and every:
stats 'myfile' nooutput
N = int(STATS_records-1)
plot for [i=0:N] 'myfile' every ::i::i pointtype (i+1)

Related

Plotting 1D data as constant functions in 2D plot with gnuplot

I have a 2D plot and want to draw horizontal straight lines from a given data file, so that each data point of the file is represented as a horizontal straight line in the existing 2D plot.
My approach so far:
I've tried using the for command, but I don't know how to write the current data point into a formular like x = C where C is the value of the data point:
for [i=1:10] "data.dat" u 2 every ::i::i
... is not what I meant.
for [i=1:10] x = "data.dat" u 2 every ::i::i
... is not a valid gnuplot command.
And furthermore, the range of i is variable, so that is another problem I have to solve with this approach.
Using arrows:
Like this posts suggests: Adding Horizontal lines on 2D plot with gnuplot. But in that example the author didn't need to draw the lines from a data file.
Is there a good way to do this?

Dots and empty dots in gnuplot

I need to draw dots and empty dots in a plot to show the fixed points. They should look like in the figure below: an empty dot (a circle) and a thick dot.
Is there any way to plot something like that?
Thanks
(source: emathematics.net)
If you wish to use the built in point types, there are usually (depending on the terminal) a filled circle and an empty circle. Issuing the test command will show you what is available. For instance, with the wxt terminal, I see
which shows me that I can get a filled circle with point type 7 and an empty one with point type 6 (we don't worry about the different colors as those are inherited from the line type).
Now, the easy way to get our desired plot is to just issue plot datafile with points pt 6 or point type 7. It is trickier if you need it to depend on your data.
Suppose that my data looks like this:
1 3 0
5 8 1
2 6 0
3 2 1
The first two columns are the x and y coordinates and the third tells me if I should use an empty dot (0) or a filled dot (1). Unfortunately, gnuplot does not support a variable point type command (something like plot datafile u 1:2:($3+6) with linespoints pt var), which is exactly what we need here.
In order to plot our data, we will make two passes. The first will plot the lines and the empty circles (for all points), and the second will plot the filled circles (for only the points that should be filled - overwriting the empty circles).
plot datafile u 1:2 with linespoints pt 6, \
datafile u 1:($3==1?$2:1/0) with points pt 7 lt 1
This command will plot the lines and the empty circles first. Next it plots the filled circles only when they are needed. To do this, it computes a conditional y-coordinate. If the third column is 1, it uses the second column as the y-coordinate. If not, it uses the invalid value 1/0, which causes gnuplot to skip the point. In order to keep the colors and everything else the same, we use lt 1 (which was used by default in the first plot command segment).
Note: I have put in a feature request for a pointtype variable option, and it looks like it may work its way into a future version. A preliminary patch is available implementing this under feature request 437.
Updated Note: The pointtype variable option is currently availabe in the development version of gnuplot.

How to plot a 2 dimensional function using data stored in a file with gnuplot

Is there any way to compute a 2 dimensional function using data from a file in gnuplot. Suppose I have a function f(x,y) which exist and I want to calculate the new values with data stored in file data.dat
i.e something like
plot f(x,y) using 'data.dat'$1:'data.dat'$2
The command plot is used for plotting one variable against another. If you want to plot a third value against two others (and obtain something that looks 3D), you'll need the splot command. In this case, the command would look like
splot 'mydata.txt' using 1:2:(f($1,$2))
The using keyword specifies what you want to plot based on the contents of a file. The 1 and 2 means that the x and y coordinates will just be the first and second column in the file. For the third coordinate we want the f(x,y) function to be used with the values from the first and second column filled in ($1 and $2).
In case we're doing something more complex than just using a column unmodified, we have to use brackets and a $-sign for the variables. So we also could have written
splot 'mydata.txt' using ($1):($2):(f($1,$2))
as the command. See the gnuplot manual for more information.

gnuplot: numerical values of points of a function

Is it possible with gnuplot (4.6) to print (in a file or through redirection from standard output) the values of the sampled points of a function.
Say, if I write plot sin(x) with for example set samples 20, I want 20 lines of data giving me the x,y values of the computed points that would be plotted.
I don't care if these are actually plotted or not.
I though that there was some kind of "text" terminal, but it seems that there is none.
This can be done with set table environment
For example:
set table "outputfile.txt"
plot sin(x)
unset table

Plotting GNUPlot graph after computation

I have a data file that lists hits and misses for a certain cache system. Following is the data file format
time hits misses
1 12 2
2 34 8
3 67 13
...
To plot a 2D graph in GNUPlot for time vs hits, the command would be:
plot "data.dat" using 1:2 using lines
Now I want to plot a graph of time vs hit-ratio, For this can I do some computation for the second column like :
plot "data.dat" using 1:2/ (2 + 3) using lines
Here 1, 2, 3 represent the column number.
Any reference to these kind of graph plotting will also be appreciated.
Thanks in advance.
What you have is almost correct. You need to use $ symbols to indicate the column in the calculation:
plot "data.dat" using 1:($2/($2 + $3))
Since you are using $n to refer to the column numbers, you now are able to use n to refer to the number itself. For example,
plot "data.dat" using 1:(2 * $2)
will double the value in the second column.
In general, you can even plot C functions like log and cos of a given column. For example:
plot "data.dat" u 1:(exp($2))
Note the parens on the outside of the argument that uses the value of a particular column.
See here for more info.

Resources