Difference between revisions of "Gnuplot"

From Noah.org
Jump to navigationJump to search
m
Line 57: Line 57:
 
== other examples ==
 
== other examples ==
  
 +
Plot the output of QtDMM (a digital multimeter recording package). The other columns in this data file contain date information which is usually wrong. This app still has a lot of bugs, but it does the job. Here I use awk to look only at the measured data. I then tell `graph` to use an automatic abscissa since my data now only has a single axis.
 +
 +
<pre>
 +
cat power_test_1.data | egrep -v "^\s*#" | awk '{print $3}' | graph --auto-abscissa 0.3 -r 0.1 -u 0.1 -h 0.8 -w 0.8 --bitmap-size 1024x768 -F HersheySans -T png | display -
 +
</pre>
 +
 +
The same plot as above but with PostScript output:
 +
 +
<pre>
 +
cat piebox305_power_test_1.txt | egrep -v "^\s*#" | awk '{print $3}' | graph -r 0.1 -u 0.1 -h 0.8 -w 0.8 --auto-abscissa -F HersheySans -T ps | display -background white -flatten -
 +
</pre>
  
 
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`.
 
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`.
Line 84: Line 95:
 
plot 'cdck-plot.dat' with lines
 
plot 'cdck-plot.dat' with lines
 
</pre>
 
</pre>
 
 
  
 
old style, depricated:
 
old style, depricated:

Revision as of 05:46, 14 January 2010


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 QtDMM (a digital multimeter recording package). The other columns in this data file contain date information which is usually wrong. This app still has a lot of bugs, but it does the job. Here I use awk to look only at the measured data. I then tell `graph` to use an automatic abscissa since my data now only has a single axis.

cat power_test_1.data | egrep -v "^\s*#" | awk '{print $3}' | graph --auto-abscissa 0.3 -r 0.1 -u 0.1 -h 0.8 -w 0.8 --bitmap-size 1024x768 -F HersheySans -T png | display -

The same plot as above but with PostScript output:

cat piebox305_power_test_1.txt | egrep -v "^\s*#" | awk '{print $3}' | graph -r 0.1 -u 0.1 -h 0.8 -w 0.8 --auto-abscissa -F HersheySans -T ps | display -background white -flatten -

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 results can be improved quite a bit if you output PostScript instead of bitmap. Other tools do a better job of converting to bitmap and you get better fonts this way.

graph -T ps -F Helvetica --x-label 'Sectors (2Kb/sec)' --y-label 'Reading time (usec)' -C  -g 3 -w 0.8 -h 0.8 -r 0.15 -u 0.075 -f 0.025 < cdck-plot.dat | display -background white -flatten -

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