[Tutor] matplotlib question - Dates not showing up on X axis
jim schmidt
txherper at gmail.com
Mon Nov 5 18:42:18 CET 2012
#!/usr/bin/python
import csv
# sudo yum install python-matplotlib
import matplotlib.pyplot as plt
from pylab import figure, show
from matplotlib.dates import YearLocator, MonthLocator, WeekdayLocator,
HourLocator, DateFormatter
from time import strftime, localtime
from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, \
MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY
import website as website
#
http://www.thetechrepo.com/main-articles/465-how-to-create-a-graph-in-python
#
http://matplotlib.org/examples/pylab_examplfes/date_demo1.htmlhttp://www.linux-support.com/cms/date-and-time-conversion-in-python/
#stats = getWebsiteStats("/scratch/google.com.csv")
#print "stats length " + str(len(stats))
def plotStats(dates, kbSec):
#plot the two lines
fig = figure()
for d in dates:
print "d: " + str(d)
dt = localtime(d)
#dt = datetime.date.timetuple(d)
print strftime('graphSites.py dates: %Y-%m-%d',dt)
ax = fig.add_subplot(1,1,1)
ax.plot_date(dates, kbSec, '-')
#ax.xaxis.set_major_locator(MonthLocator())
# locator = WeekdayLocator(byweekday=MO)
ax.xaxis.set_major_locator(WeekdayLocator(byweekday=MO))
#ax.xaxis.set_major_locator(MonthLocator())
ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
# ax.xaxis.set_minor_locator(HourLocator())
#
# ax.fmt_xdata = DateFormatter('%m-%d %H:%M')
# ax.autoscale_view()
fig.autofmt_xdate()
show()
return fig
#fig.savefig("test.png")
def test():
dates = [1352027490.953206, 1352027924.466516, 1352027930.935064]
kbSec = [24.3, 32.5, 21]
plotStats(dates,kbSec)
def plotFile(dataFileName, outputFileName):
stats = website.getWebsiteStats(dataFileName)
dates = [float(stat.timeMs) for stat in stats]
kbSec = [stat.kilo_bytes_sec for stat in stats]
fig = plotStats(dates,kbSec)
fig.savefig(outputFileName)
print "saved as " + outputFileName
test()
#plotFile("../logs/google.com.csv","../logs/google.com.png")
--
blog: homeless-by-choice.blogspot.com
This email and the files transmitted with it are the property of James J.
Schmidt and is intended soley for use of individual or entity to whom this
email is addressed. If you are not one of the named recipient(s) or
otherwise have reason to believe that you have received this message in
error, please notify the sender at txherper at gmail.com, delete this message
from your computer, destroy your computer immediately, forget all that you
have seen, and turn yourself over to the proper authorities. Any other
use, retention, observation, dissemination, consideration, recollection,
forwarding, ridicule, printing, viewing, copy or memorization of this email
without the express written consent of Major League Baseball is strictly
prohibited. The contents of this email are not to be taken literally.
Void where prohibited by law or common sense. Not valid in Rhode Island,
Guam and the Xinghua province in China. Condiments available upon request.
Cash value = 1/20th of one cent. All rights reserved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121105/9a49f113/attachment.html>
More information about the Tutor
mailing list