Gnuplot has strong support for creating three dimensional plots for functions and for properly formatted data files. In gnuplot's case, 'properly formatted' means that the data is not arranged as sets of z values with their corresponding x and y values, but as z values whose x and y values are indicated by their relative position (the Gnuplot documentation calls this 'grid' format). Thus:
z(0,0) | z(0,1) | z(0,2) |
z(1,0) | z(1,1) | z(1,2) |
z(2,0) | z(2,1) | z(2,2) |
The following tables feature the same z values, but in grid or xyz formats:
z(*,0) | z(*,1) | z(*,2) | |
---|---|---|---|
z(0,*) | 1 | 2 | 3 |
z(1,*) | 4 | 5 | 6 |
z(2,*) | 7 | 8 | 9 |
x | y | z |
---|---|---|
0 | 0 | 1 |
0 | 1 | 2 |
0 | 2 | 3 |
1 | 0 | 4 |
1 | 1 | 5 |
1 | 2 | 6 |
2 | 0 | 7 |
2 | 1 | 8 |
2 | 2 | 9 |
This demo shows some commands for producing projection plots and surface plots of three dimensional data.
Suppose we want a projection view of some data in xyz format (the data for the following samples can be downloaded here, it's just the first half of a sine wave along two axes, generated by a simple VBScript program). This can be obtained with the following:
set key off
splot 'xyz.tsv' using 1:2:3 with points palette pointsize 3 pointtype 7
Which produces the following plot. The key is turned off because
it doesn't make much sense in this plot. Notice that the zero point
of the z (vertical) axis is offset from the x and y axes. To remove
this offset, use set ticslevel 0
before the
splot
command. To remove the colour-value palette box,
use unset colorbox
.
Converting this plot to a two-dimensional 'map' style view (like a
plan view of the current plot, and sometimes known as a 'raster
plot'), can be done with the set view map
command (try
it with the plot above, without changing the other commands). Also,
the plot's appearance can be made a bit more pleasing to the eye with
some additional commands.
The ratio
refers to the height vs. width of the
points, whilst the object
commands generate a black
background.
set view map
set size ratio .9
set object 1 rect from graph 0, graph 0 to graph 1, graph 1 back
set object 1 rect fc rgb "black" fillstyle solid 1.0
splot "xyz.tsv" using 1:2:3 with points pointtype 5 pointsize 1 palette linewidth 30
These commands generate the following plot:
The pointsize
and linewidth
properties
overlap a bit in this instance; the same effect can be obtained using
a pointsize
of six and a linewidth
of
one. You might want to adjust the size of the points to either
separate them or to create a continuous 'surface'.
Home | About Me | Copyright © Neil Carter |
Content last updated: 2011-06-22