Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot: How to default to '0' when data is missing from a date sequence

I have a bunch of data that is basically a date+time with a number I'd like to plot using gnuplot. The problem is that the data is pulled from a database, so when there are times of day with zero activity, there are no rows created, so my 'csv' file I'm feeding to gnuplot has gaps in the sequence.

Plot config:

set term jpeg medium size 800,600
set output "yesterday.jpg"
set datafile separator ":"
set title "Yesterday's Uploads"
set xlabel "Hour of day (Eastern)" offset 0,-2
set ylabel "Items per minute"
unset key
set bmargin 10
set xdata time
set timefmt "%m/%d/%Y-%H-%M"
set xtics rotate
set style fill solid 0.5
plot "yesterday.stats" u 1:2 w boxes

Example data:

08/27/2013-23-00:34
08/27/2013-22-59:20
08/27/2013-22-58:79
08/27/2013-22-53:6
08/27/2013-22-52:24
08/27/2013-22-51:15
08/27/2013-22-50:12
08/27/2013-22-42:1
08/27/2013-22-38:58
08/27/2013-22-37:36

Note the missing minutes (such as from 38 to 42, and 42 to 50) where there was no activity, thus no DB entries, thus no info in my plot input file.

When I try to plot this using the config example above, the 'gaps' show up as a horizontal filled bar that is the width of the missing data.

image

I'd like the missing data to simply be a 'zero' with no activity shown on the graph. I'm thinking that there must be a way to handle this in gnuplot and wanted to check with you all before I wrote some script to insert dummy entries into my data.

Any suggestions? Perhaps a different type of plot besides boxes that doesn't "connect" the datapoints, thus leading to those odd horizontal areas?

like image 886
user2726921 Avatar asked Oct 21 '22 02:10

user2726921


1 Answers

You can specify the width of a box by the third parameter to using:

plot "yesterday.stats" u 1:2:(50) w boxes
like image 169
choroba Avatar answered Oct 27 '22 10:10

choroba