I'm using gnuplot to create a stacked histogram. Today, for the first time, all data points in one of the columns are zero. This creates a problem for gnuplot, as it now reports:
All points in histogram UNDEFINED
This is because my "using" statement has logic like:
using ($6>0:$6:NaN)
When an entire column consists of ignored values, gnuplot chokes. Is there a setting I can use to let gnuplot it should ignore this particular, and harmless issue? There will be times when the column will be zero, and this is a valid condition in the data. I'd like gnuplot to be able to handle this.
If I can't get gnuplot to handle it, I may have to issue my plot using commands differently to omit the missing dataset. I'd really rather not make this change unless I must.
Anyone out there have any suggestions?
EDIT (Adding plotscript and data file):
The plotscript and data file are generated at run time, using a combination of a template file, and script logic to determine the final script. This is fed directly to gnuplot by opening a command pipline to the gnuplot command and feeding the script directly to gnuplot.
The issue occurs today because column 6 in the graph is all zeros today. This is a good thing (no images took longer than 60 minutes to process). I would expect gnuplot to simply suppress the zero values (per the trinary operator in the 'plot' line in the plotscript), and if all values are suppressed, then there no data for that column of the histogram. Normal and expected; except gnuplot doesn't like it.
Plotscript:
set terminal 'pngcairo'
set key center under horizontal font ",8"
set style data histogram
set style histogram rowstacked
set style fill solid 1.0
set boxwidth 0.5 relative
set xtics border in scale 0.5,0.25 nomirror rotate by 45 font ",8" offset character -2, -1, 0 right
set xtics autofreq norangelimit
set ytics border in scale 0.5,0.25 nomirror norotate font ",8" offset character 0, 0, 0 autojustify
set ytics autofreq norangelimit
set y2tics border in scale 0.5,0.25 nomirror norotate font ",8" offset character 0, 0, 0 autojustify
set y2tics 1800 norangelimit
set my2tics 6
set title "Image Processing Trends"
set title offset character 0, 0, 0 font ",18" norotate
set timestamp "" bottom offset character 0,-2,0
unset xlabel
set ylabel "Nbr of Images (bars)"
set ylabel offset character 2, 0, 0 font ",8" textcolor lt -1 rotate by -270
set y2label "Avg Time in Seconds (line)"
set y2label offset character 0, 0, 0 font ",8" textcolor lt -1 rotate by -270
set zero 1e-08
set label "Generated by Luna" font ",6" tc rgb "#808080" at graph 1,-0.25 right
plot 'datafile' using (sum [i=2:4] column(i)):xtic(1) title "< 15 min" lc rgb "#00FF50", '' using ($5>0?$5:NaN) title columnhead lc rgb "#F0F000", '' using ($6>0?$6:NaN) title columnhead lc rgb "#FF0000"
Datafile:
"Date" "< 5 min" "5 - 10 min" "10 - 15 min" "15 - 60 min" "> 60 min" "Avg ET"
2012-10-26 1099 71 23 0 0 184
2012-10-29 16 0 0 0 0 81
2012-10-30 5 0 0 0 0 76
2012-10-31 650 41 24 19 0 176
2012-11-01 831 118 11 0 0 169
2012-11-02 671 158 195 91 0 353
2012-11-05 887 127 64 81 0 287
2012-11-06 1343 35 8 0 0 139
2012-11-07 1018 233 201 112 0 334
2012-11-08 1140 433 143 16 0 271
2012-11-09 1192 115 15 0 0 168
2012-11-12 1008 90 17 1 0 173
2012-11-13 911 62 5 0 0 160
2012-11-14 1066 346 219 68 0 317
2012-11-15 754 110 0 0 0 170
I have found out that for some reason gnuplot treats differently NaN and 1/0, the mathematically undefined expression that gets silently ignored (see for example the remark here). Using NaN in your logic for your column 6 with all zeros will produce an error
"<scriptname>", line xx: All points in histogram UNDEFINED
and an empty png file. Bummer. However 1/0 in your logic will produce just a warning
"<scriptname>", line xx: warning: Skipping data file with no valid points
and it will produce the plot with the rest of the data. As it is skipping the data set completely, " > 60 mins" will not appear in the legend either, which you may want.
So just change your logic for column 6 (and 5 too, if it ever becomes full of zeros) in the plot command to
plot 'datafile' using (sum [i=2:4] column(i)):xtic(1) title "< 15 min" lc rgb "#00FF50", '' using ($5>0?$5:1/0) title columnhead lc rgb "#F0F000", '' using ($6>0?$6:1/0) title columnhead lc rgb "#FF0000"
Other than the warning message informing you about no data to plot for >60 mins (which we know to begin with), this should work.
I used gnuplot v4.6 patchlevel 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With