This is an old revision of the document!


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

  • 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 y2tics auto
  • Axes labels
set xlabel ""
set ylabel ""
set x2label ""
set y2label ""
  • Graph title
set title ""
  • 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
  • New plot window
plot <...>
set term wxt 1
plot <...>
set term wxt 2
plot <...>
  • 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
# 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)

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
  • 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
software/gnuplot.1267730110.txt.gz · Last modified: 2013/09/19 16:43 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0