Hi there,
I’m trying to plot a file which keeps track of my inbox count over time. Every minute it creates an observation, recording a timestamp, and the inbox count, like this:
2009-03-25 08:33:48, 5
2009-03-25 08:34:48, 5
2009-03-25 08:35:48, 5
…
and so on. I have about a day’s worth of data so far. Here is code I’m trying to use to plot this:
import dateutil, pylab, csv, matplotlib
import numpy as npimport matplotlib.pyplot as plt
import matplotlib.dates as mdatesUsed for axis formatting
days = mdates.DayLocator() # every day
hours = mdates.HourLocator() # every month
daysFmt = mdates.DateFormatter(‘%D’)Open data file
data = csv.reader(open(‘gmail-count.txt’), delimiter=‘,’)
Convert to vectors
time =
inbox =
for c_time, c_inbox in data:time.append(c_time) inbox.append(int(c_inbox))
Plot the data
x_dates = pylab.date2num([dateutil.parser.parse(s) for s in time])
print x_datesfig = plt.figure()
ax = fig.add_subplot(111)ax.plot(x_dates, inbox, ‘g^’)
format the ticks
ax.xaxis.set_major_locator(days)
ax.xaxis.set_major_formatter(daysFmt)ax.xaxis.set_minor_locator(hours)
fig.autofmt_xdate()Save the file
plt.savefig(‘testA’)
And yet here is the result: http://screencast.com/t/gLPDFtwnJM4
I can’t figure out why the values are ‘grouping’ around particular values on the x-axis… I would expect it to look more like a function, with only one y-value for each x.
Am I using date2num wrongly, or can anyone please suggest where I might be going wrong? (In case anyone wants to see the data, I’ve attached it as well… just ignore the 3rd column)
Thanks!
Tyler
gmail-count.txt (31.3 KB)