Gnuplot seems to be a ubiquitus graphing utility in Linux
and other Unixlike operating systems. Here I provide some
basic examples for using gnuplot.
I am also working on a script to create graphics through
gnuplot on the web, plot now. Contact me for information
about the perl code.
 gnuplot
 a portable commandline driven interactive data and
function plotting utility
 command line
 start gnuplot by typing "gnuplot" in a terminal. Then try the following commands.
The resulting graphs will appear in a new window.
 plot sin(x)
The standard viewing window seems to be 10 to 10.
 plot [0:2*pi] [2:2] sin(x)
to change the viewing window enter the x interval followed by the y interval.
If you just enter the x interval gnuplot will use a suitable y interval.
 set zeroaxis
set xtics axis
plot [0:2*pi] [2:2] sin(x)
There are many options that you can set to change the usual display. See the gnuplot
documentation that accompanies your distribution.
More info below.
 input files
 another way to use gnuplot is to run it with input files, avaiding the command line.
This can be useful if you have many options to set and change. Below are some sample files
that I have used mainly in latex documents. Each example consists of the name of the file,
the file contents and a link to the result.
 line.gnuplot
 set terminal png
set output "line.png"
set y2label 'x'
set x2label 'y'
set title "y=0.5x2"
plot 0.5*x+2
 line1.gnuplot
 set terminal png
set output "line1.png"
set noborder
set size noratio
set size 1,1
set clip
set samples 160
set zeroaxis
set y2label 'x'
set x2label 'y'
set nokey
set title "Estimate the slope of this line?"
plot [10:10] 0.5*x+2
 sin_cos_png.gnuplot
 set terminal png
set output "sin_cos.png"
set size 1.25, 0.66
set noborder
set clip
set xtics axis (0,pi/2,pi,3*pi/2,2*pi)
set ytics axis (1,0.75,0.5,0.25,0.25,0.5,0.75,1)
set samples 160
set zeroaxis
set y2label 'x'
set nokey
set title "The Sine and Cosine Functions"
plot [0.05:2*pi] sin(x),cos(x) with lines
 sin_cos_tex.gnuplot
 set terminal latex
set output "sin_cos.tex"
set size 1.25, 0.66
set noborder
set clip
set xtics axis (0,"$\\frac{\\pi}{2}$"
pi/2,"$\\pi$"
pi,"$\\frac{3\\pi}{2}$" 3*pi/2,"$2\\pi$" 2*pi)
set ytics axis
(1,0.75,0.5,0.25,0.25,0.5,0.75,1)
set samples 160
set zeroaxis
set y2label '$\theta$'
set nokey
set title "The Sine and Cosine Functions"
plot [0.05:2*pi] sin(x),cos(x) with lines
 rose.gnuplot
 set terminal latex
set output "polar.tex"
set size 0.8, 1.33
set noborder
set clip
set polar
set xtics axis nomirror
set ytics axis nomirror
set samples 160
set zeroaxis
set trange [0:2*pi]
set nokey
set title "FourPedal Rose, $r=\cos(2\theta)$"
plot cos(2*t)
 lines.gnuplot
 set terminal latex
set output "lines_a.tex"
set noborder
set size square
set samples 160
set zeroaxis
unset xtics
unset ytics
set y2label '$x$'
set x2label '$y$'
set nokey
set title "Different slopes  One intersection"
plot [5:5] [5:5] x+1, x+3 with lines lt 1
set output "lines_b.tex"
set title "Same slopes  No intersection"
plot [5:5] [5:5] x+1, x1 with lines lt
1
 hexagon.gnuplot
 set terminal png transparent
set output "hexagon7.png"
set size ratio 1
set noborder
set polar
set noxtics
set noytics
set nokey
plot [0:2*pi] [2:2] [2:2] cos(t)+sqrt(3)*sin(t),
1,
cos(t)+sqrt(3)*sin(t), 2*cos(t), 2*cos(t),
cos(t)sqrt(3)*sin(t),
cos(t)sqrt(3)*sin(t), 1/(2*cos(t)),
1/(cos(t)+sqrt(3)*sin(t)),
1/(cos(t)sqrt(3)*sin(t)), 1/(2*cos(t)),
1/(cos(t)+sqrt(3)*sin(t)),
1/(cos(t)sqrt(3)*sin(t))
For help with gnuplot go to the website
http://www.gnuplot.info/.
Your documentation should be somewhere on your system like:
in Debian: /usr/share/doc/gnuplotdoc/gnuplot.html
in Fedora: /usr/share/doc/gnuplot3.7.3/gnuplot.html
online:
http://www.gnuplot.info/docs/gnuplot.html
However, this documentation is only a little better than a man page. So, there are many good
tutorials available. See
http://www.gnuplot.info/help.html
LaTeX and the gnuplot plotting program
(here in pdf) by David Klotz.
This tutorial, bundled with gnuplot sources, was written in 1991 for
gnuplot version 3.0.
It was slightly updated by the gnuplot team for gnuplot 4.0 in March 2004.
