Hi Folks,
Newbie question here...
I have a question about plotting data with irregular dates. Here's a
sample of my data (completely fabricated):
2007-06-29 20:22:03, 612
2007-07-18 09:07:03, 658
2007-07-19 11:07:05, 600
2007-07-19 15:12:07, 734
etc., etc., etc..
What I mean by this is that I'm not collecting the data at regular time
intervals. So I'd like to plot this, and have found that the plot_date
function seems to be designed for specific known time intervals. Instead
I am currently converting each timestamp to an integer in seconds since
the epoch, and then plotting that. It works fine, except that I'd then
like to be able to display the correct dates in for the x-axis rather
than integers. I'm not sure how to override the values that are
displayed on the x-axis. Can anyone help out?
Here's my current code (this is within Django - import statements
omitted):
start_date = datetime.date(2006, 3, 1)
end_date = datetime.date(2007, 3, 31)
logs = Item.objects.filter(processing_start__range=(start_date,
end_date))
dates = [float(time.mktime(p.processing_start.timetuple())) for p in
logs]
durations = [float(p.duration()) for p in logs]
matplotlib.use('Cairo')
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
ax.plot(dates, durations)
ax.set_title('Durations from %s to %s' % (start_date, end_date))
ax.grid(True)
ax.set_xlabel('Date')
ax.set_ylabel('Duration in Minutes')
canvas.draw()
imdata=StringIO()
fig.savefig(imdata,format='png')
return HttpResponse(imdata.getvalue(), mimetype='image/png')
Any help appreciated.
Thanks, Tom
···
--
----------------------------------
Tom Haddon
mailto:tom@…1682…
m +1.415.871.4180
www.greenleaftech.net