I am trying to plot data with a date on the x-axis. I am using
self.gnuplot = Gnuplot.Gnuplot(debug=1)
self.gnuplot('set xdata time')
self.gnuplot('set timefmt "%Y%m%d"') # format of the actual data
self.gnuplot('set format x "%y-%m-%d"') # for the xtics
self.gnuplot.plot(Gnuplot.Data(data,using='1:2'),Gnuplot.Func('%.2f' %
average, title='Average = %.2f' % average))
where data is, for example, something like this:
[[20090622, -113.91], [20090623, -110.59], [20090624, -124.11],
[20090625, -161.97], [20090626, -156.63], [20090627, -181.51],
[20090628, -211.62], [20090629, -211.62], [20090630, -215.41],
[20090631, -164.89], [20090702, -121.84], [20090703, -122.18],
[20090704, -108.14], [20090705, -97.77], [20090706, -120.37],
[20090707, -110.40], [20090708, -147.95], [20090709, -138.48]]
I'm passing the date as an integer in the format %Y%m%d since I wasn't
able to convince Gnuplot to accept a string. My problem is that I get
this error:
/tmp/tmpU2rqK2.gnuplot/fifo:1: line 0: illegal day of month
when the dates span two different months. In this case, it is the date
20090701 that causes the error. However, if I add 1 to all dates, this
error is avoided, since that gets rid of July 1st. It doesn't seem to
mind if there's a June 31st, or even a June 32nd if I add two.
I wonder if the data is getting mangled somewhere between my plot
command and what gnuplot tries to plot. I notice, for example, when
plotting this data:
[[20090720, -21.5], [20090721, -18.87], [20090722, -41.43], [20090723,
0.0], [20090724, -58.06], [20090725, 0.0], [20090726, -13.4]]
what I get on screen is actually
[[20090720,-18.87], [20090722,-41.43], [20090724, 0.0],
[20090724,-58.06], [20090724,0.0], [20090726,-13.4]]
Some y values are moved to the wrong day, some days are dropped
completely, and others are repeated with different values. The order
of the values, at least, is correct, although the first one was
dropped. Any ideas what could be going on?
I am using version 1.8 of Gnuplot.py and 2.6.2 of python.
|