visualizationgnuplot

Gnuplot: (High blood pressure datapoints): Plot two points against time, difference between them


I am newly disgnosed with high blood pressure and need to a) check my bp regularly now and keep a log of it and b) take medicine. You can't help me with b), but I'd need your kind help with a).

I need to keep a log of my blood pressure, therefore I need to take a few readings each day. My log looks like this:

20121001 0801 175 101
20121001 0802 Pill
20121001 1017 125 91
20121001 1537 121 101
20121001 1907 117 89
20121002 0758 191 111
20121002 0759 Pill
20121002 1003 117 98
(...)

Could you help me out with a gnuplot config file that reads the above two datapoints, plots them against the time (%Y%m%d %H%M).

The caveat here is the lines "... Pill" which I'd like to show up on the plot as a dot, a vertical line or something similar (they simply show when I have taken my pill).

Also, and I'm not quite sure if this is possible, I'd like to visualize the difference between datapoint 1 and datapoint 2, ie. 175-101=74 in the first line.

This would tremendously help me in visualizing if (and if yes, when) my pills start working.

Thank you!


Solution

  • I created the following bash script. Run it with your log file name as the argument:

    #! /bin/bash -e
    input=$1
    start=$(head -n1 "$input")
    start=${start:0:9}0000
    end=$(tail -n1 "$input")
    end=${end:0:9}2359
    
    gnuplot <<EOF
    set terminal png
    set output 'bp.png'
    set xdata time
    set timefmt '%Y%m%d %H%M'
    set xrange ['$start':'$end']
    plot '< grep -v Pill "$input"' using 1:(\$3-\$4):3:4 with errorbars pt 2 title 'Pressure', \
         '< grep    Pill "$input"' using 1:(100) with points lw 2 pt 7 title 'Pill'
    EOF
    (($?)) && exit 1
    display bp.png