Plot multiple functions from a data file in gnuplot - gnuplot

I want to plot several functions on the same plot on gnuplot using file data. One way of doing this is:
set multiplot
plot 'data.dat' using 1:2
plot 'data.dat' using 1:3
...
I want to know if there is a quicker way to do it. I have to plot around 10 functions on the same plot and that can get slow. Something like that would be ideal:
plot 'data.dat' using 1:2, using 1:3, using 1:4, ... using 1:n with lines

That's almost correct, just use
set style data lines
plot 'data.dat' using 1:2, '' using 1:3, '' using 1:4
This doesn't require multiplot mode.
With version 4.6 you can also iterate over the columns:
plot for [i=2:4] 'data.dat' using 1:i

Related

Can parameters passed to `replot` replace previous plot parameters?

The replot command can take new plot parameters and output a new plot over the previous one. This is possible because the docs say that there is an implicit comma between the previous plot and any arguments passed to replot.
Is there a setting that will take new parameters and instead apply them directly to the previous plot, or overwrite the previous parameters?
For example, say I plot:
plot sin(x)
But now I want to plot it with dots. Is there a way to modify this plot with this?
replot with dots
This type of syntax would make it easier for me to iterate on a single plot interactively until it's right.
Not exactly. But you can change the default plot style or the properties of the lines and then replot:
set style function points
plot sin(x)
set style function lines
replot
set style function linespoints
replot
set linetype 1 pointtype 7 pointinterval 5
replot

Plot one single curve with different successive colors with gnuplot

Using gnuplot I would like to plot a data set, signal vs. time (let's say a chromatogram) with different colors for selected regions of the curve (let's say peaks) but I am not sure whether it is possible or not.
What I tried so far is something like:
plot [2:4.6] [0:100] 'data.csv' using 1:2 with lines lt 1,\
[4.6:4.7] [0:100] 'data.csv' using 1:2 with lines lt 2,\
[4.7:6] [0:100] 'data.csv' using 1:2 with lines lt 3
but it does not seem to work, since I only get the 'invalid expression' message.
Use linecolor variable to dynamically specify from which line type to take the color:
lt(x) = (x >= 4.7 ? 3 : (x >= 4.6 ? 2 : 1))
plot 'data.csv' using 1:2:(lt($1)) linecolor variable
Although the method proposed by Christoph answer is good for a limited number of color changes, it may be long and complicated to set up in my case since my real data set will have many peaks and many changes of color.
I found a better one based on this question gnuplot: yerrorbars with linecolor variable, it simply consists in using a third column (which can simply be added using a spreadsheet) to set the color of every data point with the gnuplot code:
plot [2:6] [0:100] 'data.csv' using 1:2:3 linecolor variable with lines notitle

gnuplot: how to set error bars and label simultaneously

I want to plot a curve that has error bars. I used with yerrorlines for that.
Now I want to show a label for each point that should be done by: with labels
How can I use both of them simultaneously? I tried with yerrorlines ,labels but not worked!
You must plot the data twice:
plot 'data' using 1:2:3 with yerrorlines title 'title',\
'' using 1:2:4 with labels offset 0,2 notitle
You must probably adapt the label offset such that the label it doesn't overlap with the error bars.

Plot contours from one graph into another in Gnuplot

I have a data file with four columns X Y Z1 Z2 and I want to create a seperate color plot for each Z but plot contour lines from the first one also into the second one.
First I create a plot for Z1 and the contour file with
set terminal "pdfcairo" enhanced dashed size 5,5
set output "Output1.pdf"
set pm3d
unset surface
set view map
set contour
set cntrparam levels discrete 1.45,1.50
set table 'DATAFILE.contourZ1'
splot 'DATAFILE' using 1:2:3 notitle with lines
unset table
splot 'DATAFILE' using 1:2:3 notitle with lines
unset output
This gives me the color plot with two contour lines along Z1=1.45 and 1.50. So far so good. To load the contours into the second plot I tried
splot 'DATAFILE' using 1:2:4 notitle with lines,\
'DATAFILE.contourZ1' using 1:2:3 notitle with lines
but this only gives me the colorplot for Z2 without any contour lines.
Does anyone know, how I can accomplish this? If it's not possible in such an easy way as I have tried, I'm open for other ways, too :)
Thank you very much!
You have to unset pm3d before saving the table file so that you get a file with only the contour-line points.
Then if you want to plot pm3d and lines you might want to use set pm3d explicit and a splot "contour.txt" with lines, "data" with pm3d.

GNUPLOT contour over splot with pm3d from different data files

i am struggling in trying to splot a nonuniform binary matrix from a datafile1, and plot over it a contour of another variable, over the same grid but another datafile. Both the datafiles are in binary matrix shape.
# CONTOUR SETTINGS
set contour surface
set cntrparam level discrete 0.3,0.067
# PRINT CONTOUR ON TABLE
set table 'tablefile_contour'
splot 'contour_variable_field_binary' binary with l lt -1
unset table
# FIELD SPLOT
set view map;
splot 'field_to_be_plotted_2D_binary' binary with pm3d,\
'tablefile_contour' u 1:2:3 w p lt -1
basically i have been trying to follow some recipes fished along the internet.
If I try to plot only the splot, i obtain a 2D pic. I want to put on it isolines from the 'contour_variable_field_binary' file, so i splot it on a table file and i splot it together with the field to be plotted. I do it, i obtain a black pic.
How can i superimpose isolines from another file? Any clues?
Since my suggestion is a bit too long for a comment:
Have you tried plotting both original files together? You can disable contouring of the first file using nocontour, and disable the surface for the second plot with nosurface:
set contour base
set cntrparam level discrete 0.3,0.067
set pm3d map
splot 'field_to_be_plotted_2D_binary' binary with pm3d nocontour,\
'contour_variable_field_binary' binary with l lt nosurface
Can't tell if this works properly because I have not data for testing.

Resources