Notes on Gnuplot
written by A. Ernst
(, 2005-2006)
Plot data file:
plot "out" u 2:8 lt 1 lw 4 w l
replot "out" u 2:10 lt 2 pt 7
3D Plot:
set view 45,45
splot "out" u 4:5:6
Plot function:
f(x)=x**2
plot [0.0001:1000] f(x) lt 2 pt 7 lw 4
Plotting styles:
test
Symbol size/type/color:
set pointsize 10
set pointsize 0.1
Symbol type: pt
Symbol color: lt
Line width: lw
Logarithmic plots:
set logscale x
set logscale y
unset logscale x
unset logscale y
Set plot range:
set xrange [-2:2]
set yrange [-2:2]
Plot to postscript file:
set terminal postscript enhanced color
set output "out.ps"
set terminal x11
set output
Axis Labels and Plot Titles:
set xlabel "{/Symbol r}/{/Symbol r}_0"
set ylabel "dE/E_{in}"
set title "Kepler problem with time-symmetric 4th-order Hermite integrator"
Parametric Plots (e.g. Lissajous figures)
set parametric
plot [0:10*pi] sin(t),cos(t)
plot [0:10*pi] sin(t),cos(3*t)
plot [0:10*pi] sin(t),cos(4*t)
plot [0:10*pi] sin(t),cos(3*t+pi/4)
Plot vertical line with inlined data:
plot "-" w l lt 1 notitle
5 0
5 1
e
Plot different functions in different ranges:
plot (x<=0.08)||(x>=0.5)?1/0:f(x) lt 1 notitle,\
(x<=0.5)||(x>=1.0)?1/0:g(x) lt 2 notitle,\
(x<=1.0)?1/0:h(x) lt 3 notitle
Palette Plot:
set view map
set palette rgbformulae 22,13,-31
splot "out" u 2:4:5 pal
uses legend for 5th line
Grid points:
set grid
Label, Arrows:
set label "(0,0) first" at first 0, first 0
set label "(0,0) graph" at graph 0, graph 0
set label "(0,0) screen" at screen 0, screen 0
set arrow from 0,0 to 1,1
set arrow from 0,0 to 1,2
set arrow from 0,0 to 1,3
set noarrow 2
set arrow 3 to 1,5
Fitting with Gnuplot
f(x) = (1+x**2/a**2)**-2.5
FIT_LIMIT = 1e-10
a = 1.154
fit [0.1:4] f(x) "out3" u 2:4 via a
plot f(x) lt 1 title "Plummer a = 1.154 r_0",\
"out3" u 2:4 w l lt 2 title "King W_0=3"
Multiple Plots
set multiplot
set size square 0.3, 0.5
set origin 0.0, 0.5
set title "V_0 = 0.5 v_{cir}"
plot "out11" u 4:5 w l notitle
set origin 0.0, 0.0
set title "V_0 = 0.5 v_{cir}"
plot "out21" u 4:5 w l notitle
...
unset multiplot
to be continued...