Plotting 1D data as constant functions in 2D plot with gnuplot - 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?

Related

Plotting n lines each second with Gnuplot

I have to say that i am new to Gnuplot.
I have a file with 3 columns of datas and I managed plotting it with
gnuplot "name.txt" obtaining a 3D graph. Now i would want to graph n lines of that txt each second. I read that it is possible if the file update itself each second but it is not my case.
I have this file with datas that are calculated by a c++ program and represent the position of an object every second . Is it possible to live update the Graph so that you can see n points plotted each second ?
Until now I managed to do this byte Command : splot "data.txt" every ::1::10 . With this Gnuplot draw n lines form data.txt
Here is one possibility:
do for [N=10:*:10] {
splot 'name.txt' every 1::1::N using 1:2:3 with points
pause 1.0
}

Plotting heatmaps in gnuplot

So, here I am trying to plot heatmaps in gnuplot. I have a matrix-formatted text file (with row and column headers), and the command I am using to plot it is
plot "file.txt" matrix rowheaders columnheaders using 1:2:3 w image notitle
The output is this graph:
Obviously, the X and Y labels are useless like this. I believe the problem here is that gnuplot is extracting all labels from the file and plotting them. How would I go about reducing the amount of clutter in here, e.g. plotting every 10th label or so?
Thanks in advance.
Or just make the picture resolution bigger... for instance like 1920,1080 or bigger... like this:
set term pngcairo size 1920,1080
or make the tics numbers like 1000000 smaller and make a label to show that the numbers written on the tics are 1000000 bigger... or both:)
Sorry for my english...

Different markers for same data set in 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)

custom y scale in plot for

I have a data file, looking like
550 1.436e+00 7.857e-01 5.906e-01 4.994e-01 4.574e-01 4.368e-01 4.260e-01 4.273e-01 4.296e-01 4.406e-01 4.507e-01 4.639e-01 4.821e-01 5.008e-01 5.156e-01 5.378e-01 5.589e-01 5.768e-01 5.970e-01 6.196e-01 6.422e-01 6.642e-01
The first column is for x-axis, the rest ones are for the y-axis, 22 curves totally.
I want to plot the data so that y tics represent cube roots of the values. Actually, I want my cubic curves to become linear, to show, that they're cubic in the normal coordinates (and it is fixed by my task to use these coordinates).
I tried to use the following command:
plot for [i=2:23] datafile using 1:(i ** .333) smooth cspline
It expects column number in place of i.
I know, the following is correct:
plot datafile using 1:($2 ** .333) smooth cspline
giving me the desired plot for my first line. But how do I modify this for plot for?
If you want the column number in place of i, you should use column(i) in the using specification.
plot for [i=2:23] datafile using 1:(column(i) ** .333) smooth cspline

How to treat the first line of the data file as column labels in gnuplot?

I have a table like this:
A B C D E F G H I
10 23998 16755 27656 17659 19708 20328 19377 18925
20 37298 33368 53936 41421 44548 40756 40985 37294
I use this command to plot
plot "C:/file.txt" using 1:2 with lines smooth bezier, "C:/file.txt" using 1:3 with lines smooth bezier, ...
However, all the labels come out as the file name. Is it possible for gnuplot to read the first row and label the lines accordingly?
set key autotitle columnhead
plot for [n=2:12] 'vv.csv' u 1:(column(n)) w lines title columnhead(n)
n starts from 2 to skip the header.
I checked the documentation and I don't see a way to do it automatically, but you can manually set a title with
plot "file.txt" using 1:2 title "A" with lines smooth bezier ...
I once wrote a script to plot FM radio station frequencies along an axis from 87MHz to 108MHz, using the names of each radio station as vertical labels. This was not a pure gnuplot solution, the input file is processed with perl with make, but I suggest you have a look at it and see if you can use something like that.
You could also use a gnuplot toolkit such as this one for Python if you want have a lot of data to plot and you want to automate the extraction of the titles.

Resources