From LQWiki
Gnuplot is a command-line based plotting tool. It can plot data or math equations in a variety of different formats.
Contents |
Plotting
Running gnuplot will load the gnu plot command line. Making a plot involves typing a command like:
plot 'data.txt' with lines
If data.txt has two tab-delimited columns of number, this will make a 2d plot with dots (using the first column for the x-axis and the second for the y-axis) and connect them with lines.
You can also plot math functions:
plot x**2
will plot the function x^2
3d
Use the 'splot' command for plotting 3d functions:
splot -x**3 -y
plotting multiple equations
You can plot multiple equations on the same graph by seperating the equations with a comma:
plot x**2, x
splot x*y, x**2-y**4
plotting a data file
http://t16web.lanl.gov/Kawano/gnuplot/datafile-e.html
Settings
Many settings can be changed, such as the axis ranges and sampling rate. To avoid retyping the plot equation after each change, simple type replot to re-plot the previously inputted equation.
Setting the range
You can use the set command to set the ranges. The following commands set the x range to [0,10], the y range to [2,6] and the z range to [10,100000]:
set xrange [0:10]
set yrange [2:6]
set zrange [10:100000]
By default the ranges are autoscaled. You can revert them back to autoscaling with:
set autoscale x
set autoscale y
set autoscale z
If you need one of the axis to be logarithmic use set logscale AXIS<tt>. It can be turned off with <tt>set nologscale AXIS<tt>.
<tt>set logscale z
set nologscale z
Setting the grid size
In 3d this is done with set isosamples followed by the x and y rates of the sampling. Ex:
set isosamples 50, 50
Increasing the sampling rate enough will degrade performance.
Saving in different formats
Saving the graphs in different formats is done by setting the output and terminal variables.
To screen
The default behavior is to show the plot in an X11 window. This is done with:
set output
set terminal X11
Postscript
Postscript files can be printed from the command line with the lpr command.
set output "filename.ps"
set terminal postscript
replot
Postscript options
Print in color (default is monochrome):
set terminal postscript color
Use solid lines instead of dashed:
set terminal postscript solid
Encapsulated postscript
If you want to include the graph in a LaTeX document, you need to save it as an eps file:
set output "filename.eps"
set terminal postscript eps
PNG File
To save the graph as a png image:
set output "filename.png" set terminal png replot
More Examples
- plot a parametric surface in 3d space:
set parametric splot u, v, u*v
- plot a parametric curve (only use one of the parametric variables):
set parametric splot u, cos(u), u*2
External links
- Gnuplot Homepage (www.gnuplot.info)
- Online Documentation (www.gnuplot.info)
- A Useful Tutorial (www.cs.uni.edu)

This page is available under a