|
From: Tyler B <bo...@gm...> - 2009-03-25 20:49:02
|
Sorry to spam.. I was advised to re-send this as plain text. Thanks
for any help!
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 np
> import matplotlib.pyplot as plt
> import matplotlib.dates as mdates
>
> # Used 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_dates
>
> fig = 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
|