Intro to Gnuplot

sudo apt-get install gnuplot-x11

This looks like a great tool for tech students of all disciplines. The basic idea is plotting the data from an already prepared data file, e.g. "gaussian.txt"  then setting the visual parameters in gnuplot for the look/type of the graph, then running a final plot command e.g.

plot 'gaussian.txt' using (rounded($1)):(1) smooth frequency with boxes

(as in the bottom of page example). The file load of 2000 random numbers is at the site also – or generate your own from…

for i in {1..30}; do echo $RANDOM; done > random.txt

man 4 random

You can plot this as is:

gnuplot> plot 'random.txt'


There are some really good, flashy examples on the web, if some are a bit complex, written as scripts and requiring .dat files to run with – and this one IS rocket science…

You need to download and chmod his files:

./ | ./ 2 500 500 "Sine" "Cosine"

To help myself get familiar with it, here's a basic maths lesson – graphs plotted of y over x for different values of x give characteristic curve shapes that every teenage student has been tortured with at some point…they can be plotted simply by running gnuplot at the command line – command history applies as the shell:

gnuplot> plot (x)


It defaults to a y=x=0 centred plot showing pos and neg axes for valueless equations as above.

gnuplot> plot (x*x)

= (x**2)


For "y =" value equivalents you get a zero centre axes:

gnuplot> plot y=1x**2


gnuplot> plot (x*x*x)


gnuplot> plot (x*x*x*x)


The odd and even powers now just cycle the same shapes on greater scales.

Clever – it auto sizes the x/y axis scales for you!

Other interesting examples from the web page at:

3. THE plot AND splot COMMANDS

plot and splot are the primary commands in Gnuplot. They plot functions and data in many many ways. plot is used to plot 2-d functions and data, while splot plots 3-d surfaces and data.


plot {[ranges]}

{[function] | {"[datafile]" {datafile-modifiers}}}

{axes [axes] } { [title-spec] } {with [style] }

{, {definitions,} [function] …}

where either a [function] or the name of a data file enclosed in quotes is supplied. For more complete descriptions, type: help plot help plot with help plot using or help plot smooth .

3.1 Plotting Functions

To plot functions simply type: plot [function] at the gnuplot> prompt.


In general, any mathematical expression accepted by C, FORTRAN, Pascal, or BASIC may be plotted. The precedence of operators is determined by the specifications of the C programming language.

The supported functions include:

The supported operators in Gnuplot are the same as the corresponding operators in the C programming language, except that most operators accept integer, real, and complex arguments. The ** operator (exponentiation) is supported as in FORTRAN. Parentheses may be used to change the order of evaluation. The variable names x, y, and z are used as the default independent variables.

For example, try those functions above, or: gnuplot> plot sin(x)/x


gnuplot> splot sin(x*y/20)


gnuplot> plot sin(x) title 'Sine Function', tan(x) title 'Tangent'


Your data may be in multiple data files. In this case you may make your plot by using a command like:

gnuplot> plot "fileA.dat" using 1:2 title 'data A', \

"fileB.dat" using 1:3 title 'data B'

For information on plotting 3-D data, type:

gnuplot> help splot datafile

You can paste all this below in one go:


set samples 25

set isosamples 26

set title "Test 3D gnuplot"

set contour base

set hidden3d offset 1

splot [-12:12.01] [-12:12.01] sin(sqrt(x**2+y**2))/sqrt(x**2+y**2)


A good Gaussian histogram example is here: 


set key off
set border 3

# Add a vertical dotted line at x=0 to show centre (mean) of distribution.
set yzeroaxis

# Each bar is half the (visual) width of its x-range.
set boxwidth 0.05 absolute
set style fill solid 1.0 noborder

bin_width = 0.1;

bin_number(x) = floor(x/bin_width)

rounded(x) = bin_width * ( bin_number(x) + 0.5 )

plot 'gaussian.txt' using (rounded($1)):(1) smooth frequency with boxes 


Ace one liner for pwd file sizes from

gnuplot -p <(echo "set style data hist; set xtic rot by -45; plot '<(stat -c \"%n %s\" *)' u 2:xtic(1)")


Timeline plots tutorial here:

Timeline Plots with GNUPlot