Gnuplot
Contents
OverView
Here is an example how to visualize vmstat's output using gnuplot.
vmstat 1 10 | grep -v r > vmstat.txt gnuplot -p -e "plot 'vmstat.txt' using 13 title 'CPU user load' with lines, 'vmstat.txt' using 14 title 'CPU system load' with lines, \ 'vmstat.txt' using 15 title 'CPU idle time' with lines, 'vmstat.txt' using 16 title 'CPU IO wait time' with lines"
The result will look like this:
xy diagrams
lines
Maybe you do not have data for every x value. Let's say you want to plot your weight and have measured your weight on monday, tuesday and friday, but not on wednesday and thursday. In this case you must tell gnuplot as well the X as the Y coordinate of every measurement. You want a graph like this:
The above has been taken with the command
gnuplot -p -e "plot 'weight' using 1:2 with linespoints"
and the data in the file weight:
1 90 2 93 4 95 7 94 8 93 10 94
bars
Or maybe you get data from your serial port showing voltage levels for transmitting characters as to be seen on wikipedia. In this case you want a chart with bars like this:
Output to a file
To save your output as a .png file, add the commands below in bold:
gnuplot -p -e "plot 'datasource.txt' using 4 with lines;set output 'test.png';set terminal png;replot"
TroubleShooting
If you get an error message like
gnuplot -p -e "plot 'data.txt' with lines" Cannot open load file '-p' line 0: util.c: No such file or directory
You are most probably on an outdated gnuplot version. Version 4.4 differs a lot from 4.2.