2003 09 Gnuplot Visualize Data Easily for Better Presentations


Gnuplot KNOW HOW
Visualization of Acquired Data with Gnuplot
Quick on the Draw
Monthly temperatures [°C] for years 1981 - 1990
Visualizing data quickly and effec-
45
min.Temp.
tively in diagrams is a common max.Temp.
40
requirement. Gnuplot, the program
35
we will be looking at in this article,
30
has provided this functionality for
25
20
years, although admittedly Gnuplot
15
has never made the mainstream.
10
BY ALEXANDER REITERER
5
isualization of acquired data
0
might appear very specific at first
Vglance, but you don t need to be a
-5
rocket scientist to find innumerable prac- 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
Years
tical examples, such as remotely
monitoring the ambient temperature, Figure 1: Minimum and maximum monthly temperatures in Melbourne
evaluating logfiles, or displaying share
indices. For over ten years now Gnuplot sional visualization facilities and can display a cosine function. Gnuplot then
has provided a tool that, despite its handle very large amounts of data. opens a separate window and plots
slightly Spartan character based inter- Incidentally, the project has nothing to graphs based on the current basic set-
face, offers unimagined flexibility in do with the Gnu Project run by the Free tings.
combination with shell scripts and other Software Foundation; any similarity is
Plotting Simple Datasets
tools. purely coincidental. The program is nei-
Those of you who prefer a more com- ther free software nor Open Source as The data to be visualized can be derived
fortable interface will be pleased to hear defined by the Open Source Initiative. from a wide variety of sources. From
that various front-ends provide more Modifying the program is allowed, measuring devices used to collate physi-
convenient control options. These although there is a stipulation that modi- cal quantities (temperature, air-pressure,
include Kile [3], a Latex editor with inte- fications must be published as patches. humidity), but also from the Internet
grated Gnuplot front-end, and Gnuplot is included in most major dis- (such as stock exchange stats). You can
Unignuplot [4]. We will be concentrating tributions and is launched by entering also use virtual data.
on the command line here, as it provides gnuplot, which will display a prompt to No matter what method you choose,
for system independent, automated data the user. You can now enter Gnuplot spe- or where your data originated, acquired
processing. Gnuplot offers 2 or 3 dimen- cific commands, such as plot cos(x), to data will be available as a dataset of
some kind. As demonstrated in the pre-
vious section, the plot command is used
Listing 1: Plot file for monthly temperatures
to generate output. Our example simply
set xrange [-150:3800]
passed a mathematical formula to the
set xtics ("1980" 0, "1981" 365, "1982" 365*2, "1983" 365*3,U
plot command. To process data from a
"1984" 365*4, "1985" 365*5, "1986" 365*6, "1987" 365*7, "1988" 365*8,U
file, you pass the file name to plot as an
"1989" 365*9, "1990" 365*10)
argument. The file format is extremely
set title "Monthly temperatures [°C] for years 1981 - 1990"
basic: Gnuplot parses the file line by line.
set xlabel "Years"
A line represents a record, and can com-
set ylabel "Temp. [°C]"
prise multiple columns. Columns are
set grid
separated by space characters.
plot 'tempmin.dat' title "min.Temp." with lines,U
Let us assume that our dataset is
'tempmax.dat' title "max.Temp." with lines
stored in a file called example.dat and
www.linux-magazine.com September 2003 47
Temp. [ C ° ]
KNOW HOW Gnuplot
comprises a single row of numbers (one you have the option of creating a plot
Special Functions
value per line); in this case you could file. The following example creates a plot
" You occasionally need to apply specific
enter plot  example.dat to tell Gnuplot to file called temp.plt that contains the
labels to a time axis.The following com-
plot the co-ordinates as points. If you commands required by our example. You
mand is used for this purpose: set xmtics
need a different format to visualize your will need an editor to enter the com-
converts numbers to month names
data, you can use one of the plot com- mands.
(1=Jan, 2=Feb, & ), set xdtics converts to
mands style attributes, which are as Gnuplot also allows you to write the
weekdays (0=Sunday, 6=Saturday, & ). Of
follows: lines, points, linespoints, dots, commands you enter in the command
course, you could substitute y for x to
impulses, steps, fsteps, histeps, boxes, line to a plot file. This facility can be
apply this to the y axis. Undefined values
errorbars, xerrorbars, yerrorbars, xyer- enabled using the save option filename
are assigned a value, for example 13 will
rorbars, boxerrorbars, boxxyerrorbars, syntax, where option is either functions,
result in Jan.
vector, financebars, candlesticks (Figure variables or set. If you do not specify any
" The following commands hide an axis: set
2 shows a selection of output formats). options, the current sets, functions, vari-
xzeroaxis, set yzeroaxis, set zzeroaxis
The syntax is always: plot  file with style ables and the last plot and/or splot
" The set logscale axis base applies a loga-
The plot command provides a number command are saved. load  filename will
rithmic scale to an axis.
of useful parameters for visualizing large load the file again.
amounts of data. The requirement will The ~/.gnuplot file plays a special
be not to display the whole range of role. If available, it is parsed on launch- hide it. The set xtics command allows
data, but a selection. For example plot ing Gnuplot. In other words, you can use you to apply individual labels to the X
 example.dat using 2:3 would output the file to store basic preferences, which axis. set grid will display a grid. The fol-
only the second and third columns. are then applied whenever you launch lowing command defines the range for
the program. the plot: set xrange [xmin:xmax]. See the
A Simple Example
example in Listing 1.
Multiple Datasets
The aim for this example is to plot an
Error Bars
attractive graph of the monthly tempera- Our example will be plotting multiple
tures for Melbourne, Australia, for the datasets as a single graph. The following One typical requirement is to plot erro-
years 1981 through 1990. The figures commands are required: plot  temp- neous measurements or deviations along
were supplied by a meteorological sta- max.dat title  max. Temp. with lines, with the acquired data. The with error-
tion and are stored in files called  tempmin.dat title  min. Temp. with bars command provides this facility. To
tempmin.dat and tempmax.dat (mini- lines do so, you need to place the starting
mum and maximum monthly set commands are used to define titles point and endpoint of the error bar in a
temperatures, respectively). The temper- and labels. set title  Title will set the column of their own within the data set.
ature figures in the files are stored in a diagram title, set xlabel  X-label sets the If you only use one column to define
single column. label for X axis and ylabel for the Y axis. error bars, or if the use of columns is
When you are plotting complex graphs set key x,y will set the key to position x:y. delimited by a command such as using
it may not be very effective to enter the If you do not require a key for the cur- 1:2:3, Gnuplot will refer to the third col-
commands involved sequentially. Thus, rent diagram, you can use set nokey to umn to dimension the error bar. The
Listing 2: Plot file for error
bars
set title "Average (fictional) U
income"
set xlabel "Years on staff"
set ylabel "Income [Dollars]"
set xrange [-1.5:48]
plot 'income.dat' title U
"Income" with boxes, U
'income.dat' title "Deviation" U
with errorbars
Listing 3: Extract from
3dpoints.dat
-31 -194 -661
58 149 -605
-2 188 -599
...
Figure 2: Three different output styles using the plot commands (with points, with lines, with impulses)
48 September 2003 www.linux-magazine.com
Gnuplot KNOW HOW
tax is: set view rot_x, rot_z, scale_x,
Listing 4: Plot file for Listing 5: Postscript Output
scale_z. You should be aware of the per-
3D-Plot example
missible rotation intervals; rot_x must lie
set terminal postscript color
between 0 and 180 degrees, rot_z
set title "3D-Plot of U set output 'filename.ps'
between 0 and 360 degrees. The default
co-ordinate points" replot
settings are: 60 degrees for rot_x, and 30
set data style lines
degrees for rot_z. Our example: set view
set contour base
50, 10, 1.0, 1.0. set hidden3d will hide
set surface Listing 6: Encapsulated
any hidden line segments to enhance the
set hidden3d
Postscript Output
3D effect.
set view 50,10,1.0,1.0
set terminal postscript eps U
If you want Gnuplot to plot co-ordi-
set dgrid3d 40,51,3
color
nates with an irregular distribution, you
show contour
set output ' filename.eps'
should look to closing the gaps in the
splot '3dpoints.dat' title "Grid"
replot
distributed coordinates using interpola-
tion. You can use the set dgrid3d to do
value is then interpreted as the differ- so. You need to tell the command the
Listing 7: Latex Output
ence to the value of the function number of intervals along the x and y
set terminal latex
(function value +/- deviation). axes, and additionally supply a weight-
set output 'filename.tex'
If the user specifies with boxes in addi- ing factor. In our case: set dgrid3d
replot
tion to error bars, the acquired data will 40,51,3.
be displayed as a bar chart and the devi- set ticslevel manipulates the starting
ations as impulses. Listing 2 contains the point of the vertical axis. The default set- The facility for issuing Latex-specific
plot file for our example. ting is 0.5. commands from within set commands
Listing 4 shows the final plot file for (labels, titles, & ) using $ and \\ is partic-
3D Plots
our example. ularly useful. For example: set title
Acquired data commonly needs to be  \LaTeX\ - $ \gamma $  .
Output
visualized in 3D. Instead of the plot com-
Help and Recommended
mand, you can use the splot command to As most users tend to embellish other
Reading
do so. The following example visualizes documents with diagrams, it is a good
a set of 3 dimensional measuring points. thing that Gnuplot provides a variety of As the full range of Gnuplot functions is
The co-ordinates of these points are export functions. You simply redirect the far larger than the scope that this article
stored in X Y Z format in a file called output to a file. The set terminal com- could possibly cover, readers are recom-
3dpoints.dat: mand is used for this purpose. set output mended to investigate the comprehen-
There are a number of special com-  filename then creates an output file. sive help system. Typing help keyword
mands for three-dimensional plotting The following sections show commands will provide help on the chosen key-
with Gnuplot. set view manipulates the used to create Postscript (see Listings 5 word. Just typing help calls up the help
user s fictive view of 3D graph. The syn- and 6) and Latex files (see Listing 7). system. Documentation on Gnuplot is
available on the Internet from [2], [5]
and [6], amongst other sites. The man-
3D-Plot of co-ordinate points
ual is available from the Gnuplot
Grid
homepage [1]. %
-600
-700
-800
INFO
[1] Gnuplot Homepage:
http://www.gnuplot.info/
-500
-550
[2] Gnuplot Tutorial: http://www.duke.edu/
-600
~hpgavin/gnuplot.html
-650
250
-700
[3] Kile Homepage:
200
-750
http://kile.sourceforge.net/
150
-800
100
-850 [4] Unignuplot Homepage:
50
-900
http://unicalculus.sourceforge.net/
0
-50 [5] Gnuplot Manual: http://www.
-100
tu-chemnitz.de/urz/anwendungen/grafik/
-150
gnuplotdoc.html
-300 -200
-200
-100
0
-250
100 [6] Gnuplot FAQ: http://www.ucc.ie/gnuplot/
200
300
gnuplot-faq.html
Figure 3: 3D-Plot
www.linux-magazine.com September 2003 49


Wyszukiwarka

Podobne podstrony:
2003 09 Genialne schematy
Dz U 2003 190 1864 zmiana z dnia 2003 09 12
2003 09 Sterownik dzwonka szkolnego
2003 09 Szkoła konstruktorówid!703
2003 09 Szkoła konstruktorów klasa II
2003 09 Komodo, Clustering Mandrake, Mathematica5
For the Present & The Other Side of the Stars
Spatial Visualization for Heterogeneous Cinema Venue Data
karlsen & snodgrass (2003) The word frequency paradox for recall or recognition
Magazine Asimov s Science Fiction 2003 Issue 09 September (v1 0) [txt]
dz u nr153 poz1504 1 09 2003 a
09 14 Analiza FOR Mlodzi wyksztalceni
Anti Aliasing, Analog Filters For Data Acquisition Systems
PMI WB SemPP! 10 09 PRINCE2 Overview for PMI
2006 09 Life Boat Using Tar to Prepare for an Emergency

więcej podobnych podstron