Running
gnuplot
Start interactive prompt
gnuplot <script.gp>
Run a script file
gnuplot -persist -e "plot sin(x)"
Plot and keep the window
gnuplot -e "<cmds>" <script.gp>
Run a command, then a script
Commands and files run in the order given; use -e to pass
variables, e.g. -e "file='a.dat'".
gnuplot -c <script.gp> <args>
Script with arguments
Inside the script the arguments are ARG1, ARG2, ... and ARGC.
gnuplot -
Read commands from stdin
load '<script.gp>'
Run a script from the prompt
help <topic>
Built-in help
pause mouse close
Keep window open until closed
Useful in scripts so the plot window does not vanish.
show <setting>
Show the current setting
Plotting
plot <expr>
Plot a function of x
plot '<file>'
Plot a data file (column 1 vs 2)
plot '<file>' using 1:3
Pick columns for x and y
plot '<file>' using 1:($2*2)
Compute with column values
Parentheses make an expression; $2 is column 2.
plot '<f1>', '<f2>'
Several datasets in one plot
plot <a>, <b> title
'<name>'
Name a curve in the legend
plot ... notitle
Leave a curve out of the legend
plot [<x0>:<x1>] [<y0>:<y1>]
<expr>
Set ranges for this plot
plot '<file>' skip 1
Skip header lines
plot '<file>' using 1:2:3 with
yerrorbars
Error bars
plot '<file>' using 1:xtic(2)
Use column 2 as tick labels
plot '<file>' using 1:2 smooth csplines
Smooth the curve
plot '<file>' using 1:2 axes x1y2
Plot on the second y axis
plot '-'
Read inline data until e
plot '< <cmd>'
Plot output of a shell command
The text is passed to the shell; the output is read as data.
plot for [i=1:5] '<f>'.i.'.dat'
Loop over files
replot
Redraw the last plot
Output
set terminal png size 800,600
Raster image
set terminal pngcairo size 800,600
Image with cairo (nicer text)
set terminal svg size 800,600
Vector SVG
set terminal pdfcairo size 6in,4in
PDF output
set terminal dumb
Text plot in the terminal
set output '<file>'
Write output to a file
unset output
Close the output file
set terminal
List available terminals
set term pdfcairo; set output '<f>';
replot
Re-save the current plot
Recipes
PNG from a CSV, one command
gnuplot -e "set datafile separator ','; set term png size 800,500; set output 'out.png'; plot 'data.csv' using 1:2 with lines title 'value'"
Reusable script with arguments
set terminal svg size 800,500set output ARG2set gridplot ARG1 using 1:2 with lines notitle
Fit a line and show the result
f(x) = a*x + bfit f(x) 'data.dat' using 1:2 via a,bset key top leftplot 'data.dat' title 'data', f(x) title sprintf('%.2fx+%.2f', a, b)
Plot a pipeline straight from the shell
awk '{print $1, $3}' log.txt | gnuplot -persist -e "plot '-' with lines"
Two plots on one page
set terminal pngcairo size 900,500set output 'two.png'set multiplot layout 1,2plot sin(x)plot cos(x)unset multiplotunset output