This is an old revision of the document!
Table of Contents
GnuPlot
Enter gnuplot environment with 'gnuplot' command. In the interactive shell you can use the following commands.
load
To load a command file, which contains other commands for the gnuplot interactive shell. Lines starting with '#' are ignored.
load "plot_data.gnuplot"
You can also directly load it when starting gnuplot, in shell:
gnuplot -persist plot_data.gnuplot
set
- Window size
set term wxt size 1024,768 set term x11 size 1024,768
- Axes ranges
set xrange [0:1000] set yrange [-100:100] set x2range [0:100] set y2range [-10:10] set autoscale
- Axes tics
set ytics nomirror set y2tics -3.5,0.5,3.5 set ytics ("0.5" 0.5, "1.2" 1.2, "2.3" 2.3) set y2tics auto
- Axes tics labels
set format x "%f" set format y "%e"
- Grid
set grid
- Axes labels
set xlabel "" set ylabel "" set x2label "" set y2label ""
- Graph title
set title ""
- Legend position
# available: left, right, top, bottom, outside, and below set key left bottom set key 100,100
- Line options
set pointsize 0.33333333
- Multiplot
set multiplot set size 0.5,1.0 set origin 0,0 plot <...> set size 0.5,1.0 set origin 0.5,0 plot <...> unset multiplot
set multiplot layout 1,2 title "global title" plot <...> plot <...> unset multiplot
- New plot window
plot <...> set term wxt 1 plot <...> set term wxt 2 plot <...>
- Data separator (space by default)
set datafile separator ","
- Clear window
clear
plot
Plot data from a file
- With only one or two columns in the file.
plot "data.dat"
- Specifying columns to use. If only one is specified, entry number (line number) is used for x.
plot "data.dat" using 4 plot "data.dat" using 4:5
- Specifying lines to use (every 2 lines from line 50 to line 1050)
plot "data.dat" using 4:5 every 2::50::1050
- Several curves in the same plot
plot "data1.dat" using 4:5, "data2.dat" using 6:7
- Functions titles
plot "data1.dat" using 4:5 t "my curve"
- Colors
show palette colornames plot "data1.dat" using 4:5 lt rgb "red" plot "data1.dat" using 4:5 lt rgb "#FF0000"
- Axes : x1y1 (bottom-left), x2y2 (top-right), x1y2, x2y1
plot "data1.dat" using 4:5 axes x1y1, "data2.dat" using 6:7 axes x1y2
If you want to display different tics on y2 axis, do before the plot command:
set ytics nomirror set y2tics -3.5,0.5,3.5 # or set y2tics auto
- Line type
# line plot "data1.dat" using 4:5 with lines # line with custom style plot "data1.dat" using 4:5 with lines linestyle 1 # line with custom line width plot "data1.dat" using 4:5 with lines lw 4 # points plot "data1.dat" using 4:5 with points # points of custom type plot "data1.dat" using 4:5 with points pt 19 # lines AND points plot "data1.dat" using 4:5 with linespoints pt 1 # labels in addition to points plot "data1.dat" using 4:5:1 with labels offset 0.7,0.7 # to find out point types and line width available test
- Arithmetics on columns
plot "data1.dat" using 4:($5/2+14) # where $n means column n
You can use very complicated formulas, define functions and do computations before the plot command. For instance to rotate and translate a trajectory before to display it:
theta=7.72 * (2*pi/360) dx=6.7866 dy=10.1704 rotation_x(x,y)=(x-dx)*cos(theta)-(y-dy)*sin(theta) rotation_y(x,y)=(x-dx)*sin(theta)+(y-dy)*cos(theta) plot "gps.dat" using (rotation_x($3,$4)):(rotation_y($3,$4))
- Using cumulated values of a column
plot "< awk '{sum=sum+$2; print sum,$6}' idSlamDala.dat" using 1:2 # sum of column 2
- Plotting one curve with values from different files
plot "< paste file1.dat file2.dat" using 1:($4-$2)
- Using directly a data file compressed with gzip
plot "< gunzip -c file.dat" using 1:($4-$2)
etc with shell commands…
File outputs
In general be sure that you don't have another “set term” command in your plotting code.
- EPS and PDF:
set terminal postscript eps color "Times-Roman" 16 set output 'plot.eps' # you plotting code (can be included using the load command) set output !epstopdf --outfile=plot.pdf plot.eps quit
By default, when exporting to ps or pdf, gnuplot changes the lines style with dashes so that they can be recognized when printed in black and white. If you want to keep your lines plain, you can add the “linestyle 1” command:
plot [...] with lines linestyle 1 lt rgb "red"
- PNG:
set terminal png size 450,360 small set output 'plot.png' # you plotting code (can be included using the load command) quit
- SVG:
set terminal svg rounded size 450,360 set output 'plot.svg' # you plotting code (can be included using the load command) set output !gzip -S z plot.svg quit