Suppose you have some measurements which you have put in a file data1 which looks like this:
#x y error 0 0 0 1 0.11 0.01 2 0.39 0.02 3 0.92 0.02 4 1.59 0.03
The line which starts with a # is a comment line.
To generate a plot of second column with respect to the first one just enter
plot "data1" | |
If the third column is to be interpreted as possible error, enter
plot "data1" with errorbars Some of the parts of the command may be shortened: p "data1" w errorbars is equivalent. | |
To plot, for example third column as a function of the first column,
p "data1" using 1:3 or p "data1" u 1:3 is equivalent. | |
You can also use using to form functions of the data values for plots.
For example,
p "data1" u ($1*$1):2 will plot the second column as a function of the square of the first column. | |
To plot with lines instead of points,
p "data1" with lines or p "data1" w l is equivalent. | |
To change the ranges of the axes,
p [1:5][-1:] "data1" with linepoints or p [1:5][-1:] "data1" w lp is equivalent. | |
To superimpose a second plot, just add another set of parameters after a comma:
p "data1" w lp , 0.1*x*x | |
You can add labels to x and y axes, to the different curves, etc:
set label "j" at 1,0.6
When you have to enter this many commands to generate a plot, it becomes more practical to put these commands into a file, and then load them in gnuplot. For example, create a file named Figure1.gp with the following contents: set label "j" at 1,0.6 set xlabel "time" set ylabel "displacement" p "data1" w lp title "second column"and then just enter load "Figure1.gp" in gnuplot. This way, you will not have to re-write all commands when you want to make adjustments to the figure. |
Once you have given your figure its final shape, you can add two lines to your Figure1.gp file as shown below to generate the plot in an image file:
# You can use comment lines that start with a # set term jpeg set out "Fig1.jpg" set label "j" at 1,0.6 set xlabel "time" set ylabel "displacement" p "data1" w lp title "second column"This will result with the figure in the file Fig1.jpg (instead of on the screen) when you enter
l "Figure1.gp"
in gnuplot.