version 3, including all changes.
.
Rev |
Author |
# |
Line |
1 |
JohnMcPherson |
1 |
The old-school Unix way of generating graphs from numeric data. It has very verbose documentation, but unfortunately it lacks in practical examples. |
|
|
2 |
|
|
|
3 |
!!!Hints |
|
|
4 |
!! Output format |
|
|
5 |
By default, gnuplot creates [X11] windows and draws the graphs to your [XServer]. But that's no good for embedding it into a report, so do: |
|
|
6 |
<verbatim> |
|
|
7 |
set output "filename.ps" |
|
|
8 |
set term postscript color |
|
|
9 |
[...] |
|
|
10 |
plot [your plot command] |
|
|
11 |
</verbatim> |
|
|
12 |
|
|
|
13 |
If you use [LaTeX], you can get gnuplot to output a LaTeX picture instead of embedding a graphic in your report: |
|
|
14 |
<verbatim> |
|
|
15 |
set output "foo.tex" |
|
|
16 |
set term latex |
|
|
17 |
[...] |
|
|
18 |
plot [your plot command] |
|
|
19 |
</verbatim> |
2 |
JohnMcPherson |
20 |
Note that your latex file should "\usepackage{latexsym}" so that it knows about several shapes that gnuplot outputs (such as \Diamond and \Box). Try "help set term latex" for more info. |
1 |
JohnMcPherson |
21 |
|
|
|
22 |
!!Vertical Lines |
|
|
23 |
The default is to give a function that calculates "y" for various values of "x", but that makes it difficult to get a vertical line. Do |
|
|
24 |
<verbatim> |
|
|
25 |
set parametric |
|
|
26 |
# vertical line |
|
|
27 |
plot 0, t |
|
|
28 |
# horizontal |
|
|
29 |
plot t, 0 |
|
|
30 |
# or just plain old |
|
|
31 |
plot 5 |
|
|
32 |
</verbatim> |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
!!Multiple columns from the same data file |
|
|
36 |
<verbatim> |
|
|
37 |
set pointsize 2 |
|
|
38 |
# plot [xrange] [yrange] function, function, .... |
|
|
39 |
# do columns 3,4 and 6, using the first column for x |
|
|
40 |
plot [0:2] [0:100] "input" using 1:3 with linespoints title "3rd", \ |
|
|
41 |
"input" u 1:4 w lp t "4th", "input" u 1:6 w lp t "6th" |
|
|
42 |
</verbatim> |
|
|
43 |
As you see, command names can be shortened, which can |
|
|
44 |
make it hard to understand what is happening :) |
3 |
AlastairPorter |
45 |
|
|
|
46 |
!!Multiple plots on a single page |
|
|
47 |
Say you want to put 2 graphs on a single A4 bit of paper to print it out |
|
|
48 |
<verbatim> |
|
|
49 |
set terminal postscript portrait |
|
|
50 |
set size 1,1 # The documentation recommends you set to full size first |
|
|
51 |
set origin 0,0 |
|
|
52 |
set output "output.ps" |
|
|
53 |
set multiplot # Enter multiplot mode. Your prompt will become 'multiplot>' |
|
|
54 |
set size 1,0.5 |
|
|
55 |
set origin 0,0 |
|
|
56 |
plot "input" using 1:2 with lines |
|
|
57 |
set size 1,0.5 |
|
|
58 |
set origin 0,0.5 |
|
|
59 |
plot "input" using 1:3 with lines |
|
|
60 |
unset multiplot # Exit multiplot mode |
|
|
61 |
</verbatim> |
|
|
62 |
|
|
|
63 |
!! Plotting timeseries data |
|
|
64 |
<verbatim> |
|
|
65 |
set xdata time |
|
|
66 |
set timefmt "%H:%M:%S" |
|
|
67 |
set xrange ["8:00:00":"18:00:00"] |
|
|
68 |
</verbatim> |
|
|
69 |
Timestamps in your data file will now be recognised. Gaps in your time data will show up as gaps in the graph. |
|
|
70 |
|
|
|
71 |
!! Normal distribution |
|
|
72 |
Define the following: |
|
|
73 |
<verbatim> |
|
|
74 |
invsqrt2pi=1.0/sqrt(2.0*pi) |
|
|
75 |
normal(x,mu,sigma)=invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2) |
|
|
76 |
</verbatim> |
|
|
77 |
Now, if you want a normal distribution with mean 13 and SD 1, you can go |
|
|
78 |
<verbatim> |
|
|
79 |
plot normal(x,13,1) |
|
|
80 |
</verbatim> |
|
|
81 |
|
|
|
82 |
!! Force a scale |
|
|
83 |
<verbatim> |
|
|
84 |
set xrange[0:10] |
|
|
85 |
set yrange[50:100] |
|
|
86 |
</verbatim> |