2010/11/10

gnuplot for people who have no interest in learning gnuplot

A really quick tutorial to get you started with gnuplot. Just start the gnuplot executable to enter the gnuplot CLI.

Plotting a basic function

gnuplot> plot x**3-4*x**2+sin(x)/x 
will plot the function x3-4x2+sin(x)/x.

Disabling the function label/legend on the top right

gnuplot> unset key
gnuplot> replot  
Will remove the label in the top right corner of the output and redraw the graph.

Outputting to pdf

gnuplot> set terminal pdf
Terminal type set to 'pdfcairo'
Options are ' size 5.00in, 3.00in '
gnuplot> set output "somefile.pdf"
gnuplot> replot
gnuplot> unset output 
Will create a new file called somefile.pdf, write it's output to it (that's what the replot command is for) and finally close the file so you can open it (unset output).

If you prefer outputting to png or jpg, just use set terminal png and set the output accordingly.

Restoring the output to standard after writing to pdf

gnuplot> set terminal pop
   restored terminal is wxt 0 

Only plotting a certain domain

gnuplot> plot [x=-1:1] x**3

Drawing the x-axis

gnuplot> set xzeroaxis
gnuplot> replot         

Setting the axis labels

gnuplot> set ylabel "data"
gnuplot> set xlabel "time"
gnuplot> replot    

That should be enough to get you started. If you'd like to know more, just check out the documentation for gnuplot.

No comments:

Post a Comment