Difference between revisions of "Gnuplot"

From Noah.org
Jump to navigationJump to search
m
Line 61: Line 61:
  
 
<pre>
 
<pre>
graph -F HersheySans -T png --bitmap-size 800x600 --x-label 'Sectors (2Kb/sec)' --y-label 'Reading time (usec)' -g 4 -w 0.8 -h 0.8 -r 0.15 -u 0.075 -f 0.025 < cdck-plot.dat | display -
+
graph -F HersheySans -T png --bitmap-size 800x600 --x-label 'Sectors (2Kb/sec)' --y-label 'Reading time (usec)' -C -w 0.8 -h 0.8 -r 0.15 -u 0.075 -f 0.025 < cdck-plot.dat | display -
 
</pre>
 
</pre>
  

Revision as of 18:31, 29 November 2009


I use gnuplot and GNU plotutils from time to time. They are unrelated. I prefer the traditional UNIX pipeline filter and toolkit style of the GNU plotutils. It is also easier to use and more often then not it just works. The gnuplot tool produces nicer looking graphs and has a lot more features (including interactive 3D graphs).

Most of the time I just want to plot some 2D data points from a file or stream so I use GNU plotutils.

graph -F HersheySans -T png < cdck-plot.dat | display -

[[1]]

[gnuplot documentation]

gnuplot

First I do is alias "gnuplot" to "gnuplot -persist":

alias gnuplot='gnuplot -persist'

You can also put this in your gnuplot script when you set the terminal:

set terminal x11 persist

This will tell gnuplot to keep an image displayed on the screen. By default gnuplot will close a display window as soon as it finishes drawing.


I don't run an ntp daemon.Instead, I just sync my clock once a day using ntpdate. The ntpdate log file looks like this:

28 Jul 04:02:41 ntpdate[4781]: step time server 192.43.244.18 offset 13.828862 sec
29 Jul 04:02:45 ntpdate[19059]: step time server 192.43.244.18 offset 13.838561 sec
30 Jul 04:03:36 ntpdate[17510]: step time server 192.43.244.18 offset 13.844762 sec

I save the output from ntpdate to a log file. I can plot the daily clock drift using this gnuplot script:

set terminal x11 persist
set data style errorlines
set title "Daily clock offset\nnegative means clock runs fast"
set xlabel "Date"
set xdata time
set timefmt "%d %b %H:%M:%S"
set format x "%d/%m"
set ylabel "Required offset (negative minutes fast)"
set yrange [ -1.0 : 30.0]
set grid
plot "ntpdate.log" using 1:10

other examples

Plot the output of `cdck` using GNU Plotutils. Note that you could just use -T X for output and skip the pipe into `display`, but I wanted to demonstrate the pipeline abilities of `graph`.

graph -F HersheySans -T png --bitmap-size 800x600 --x-label 'Sectors (2Kb/sec)' --y-label 'Reading time (usec)' -C -w 0.8 -h 0.8 -r 0.15 -u 0.075 -f 0.025 < cdck-plot.dat | display -

The equivalent using gnuplot with `cdck`. Can't be done with a stream, I'm afraid. The results is nicer looking.

#!/usr/bin/env gnuplot
set terminal x11 persist
set data style errorlines
set grid
set xlabel 'Sectors (2Kb/sec)'
set ylabel 'Reading time (usec)'
set format y "%12.f"
set format x "%12.f"
#set logscale y
plot 'cdck-plot.dat' with lines


old style, depricated:

set terminal png 
#gif small size 640,480
set title "Daily clock offset\nnegative means clock runs fast"
set data style fsteps
set xlabel "Date"
set timefmt "%d/%m/%y\t%H%M"
set yrange [ -4.6 : -4.8]
set xdata time
set xrange [ "25/06/00":"29/08/00" ]
set ylabel "Required offset (negative minutes fast)"
set format x "%d/%m"
#\n%H:%M"
set grid
set key left
plot "data.dat" using 1:10
reset