Calculating Boolean values ​​in a graph based on time

I am drawing a graph based on time and would like to add a sequence of boolean data to it.

Is it possible for boolean data to highlight the entire height of the graph canvas where the value is true?

Plotfile:

set datafile separator ","
set terminal pngcairo size 800,400
set title "Solar charge monitor"
set yrange [0:]
set ylabel "V"
set y2range [0:]
set y2label "A"
set y2tics
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set key left top
set grid
set output "samplePlot.png"
plot "sampleData.csv" using 1:2 with lines lw 2 title 'Batt (V)', \
     "sampleData.csv" using 1:3 with lines lw 2 title 'Solar (V)', \
     "sampleData.csv" using 1:4 with lines lw 2 title 'Charge (A)' axes x1y2, \
     "sampleData.csv" using 1:5 with lines lw 2 title 'Load (A)' axes x1y2

      

Sample data:

time,V_Batt,V_SolarV,A_Charge,A_Load,bool_charging
2014-09-25T07:06:03.358Z,13.20,14.38,0.52,0.03,1
2014-09-25T07:05:03.639Z,13.16,14.14,0.52,0.05,1
2014-09-25T07:04:02.856Z,13.18,14.19,0.54,0.03,1
2014-09-25T07:03:03.141Z,13.18,14.24,0.52,0.03,1
2014-09-25T07:02:03.410Z,13.18,14.09,0.52,0.03,1
2014-09-25T07:01:03.604Z,13.20,14.38,0.54,0.03,1
2014-09-25T07:00:02.766Z,13.11,14.28,0.50,0.02,1
2014-09-25T06:59:03.025Z,13.09,14.28,0.48,0.02,1
2014-09-25T06:58:03.302Z,13.11,14.28,0.43,0.02,1
2014-09-25T06:57:03.445Z,13.18,14.28,0.56,0.05,1
2014-09-25T06:56:02.611Z,13.16,14.14,0.52,0.03,1
2014-09-25T06:55:02.901Z,13.09,14.58,0.48,0.01,1
2014-09-25T06:54:03.178Z,13.09,14.48,0.52,0.02,1
2014-09-25T06:53:03.432Z,13.13,14.53,0.54,0.06,1
2014-09-25T06:52:03.630Z,13.11,14.28,0.48,0.03,1
2014-09-25T06:51:02.763Z,13.16,14.14,0.54,0.05,1
2014-09-25T06:50:03.068Z,13.16,14.28,0.54,0.03,1
2014-09-25T06:49:03.388Z,13.07,14.38,0.50,0.03,1
2014-09-25T06:48:02.683Z,13.09,14.33,0.50,0.03,1
2014-09-25T06:47:02.967Z,13.07,14.04,0.48,0.02,1
2014-09-25T06:46:03.249Z,13.05,14.19,0.48,0.02,1
2014-09-25T06:45:03.410Z,13.09,14.24,0.56,0.06,1
2014-09-25T06:44:02.677Z,13.07,14.24,0.52,0.03,1
2014-09-25T06:43:02.973Z,13.05,14.09,0.50,0.03,1
2014-09-25T06:42:03.282Z,13.09,14.24,0.52,0.03,1
2014-09-25T06:41:03.389Z,12.96,14.04,0.46,0.02,1
2014-09-25T06:40:02.702Z,12.76,13.59,0.50,0.00,1

      

I would like to add column 6 which is boolean (0/1). In this sample data, the background will be fully highlighted since bool is always true

Any advice?

+3


source to share


1 answer


You can use the plot style boxes

to draw backgrounds depending on the value of column 6, i.e. something like

plot "sampleData.csv" using 1:($6 * 16) with boxes fc rgb '#ccffcc' fillstyle solid,\
     "" using 1:2 lt 1 with lines lw 2 title 'Batt (V)'

      

This, however, requires you to know the maximum and minimum values ​​of the y-range. If this needs to be calculated automatically, you need to first create a dummy chart with a terminal unknown

and then use GPVAL_Y_MIN

and GPVAL_Y_MAX

:

reset
set datafile separator ","
set terminal pngcairo size 800,400
set title "Solar charge monitor"
set yrange [0:]
set ylabel "V"
set y2range [0:]
set y2label "A"
set y2tics
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set key left center
set grid
set autoscale xfix
set style data lines

set terminal push
set terminal unknown
plot "sampleData.csv" using 1:2, "" using 1:3
set terminal pop

set output "samplePlot.png"
plot "sampleData.csv" using 1:(GPVAL_Y_MIN + $6 * (GPVAL_Y_MAX - GPVAL_Y_MIN)) with boxes fc rgb '#ccffcc' fillstyle solid notitle,\
     "" using 1:2 lt 1 lw 2 title 'Batt (V)', \
     "" using 1:3 lt 2 lw 2 title 'Solar (V)', \
     "" using 1:4 lt 3 lw 2 title 'Charge (A)' axes x1y2, \
     "" using 1:5 lt 4 lw 2 title 'Load (A)' axes x1y2

      

Using a slightly modified data file (I inserted some zeros to show the effect) I get:



enter image description here

If you don't need vertical lines on the borders, you can also use filledcurves

with:

...
plot "sampleData.csv" using 1:(GPVAL_Y_MIN + $6 * (GPVAL_Y_MAX - GPVAL_Y_MIN)) with filledcurves x1 fc rgb '#ccffcc' fillstyle solid notitle,
...

      

enter image description here

+3


source







All Articles