Menu

[r271]: / trunk / htdocs / examples / test.py  Maximize  Restore  History

Download this file

47 lines (32 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import datetime, time
class intdate(int):
'''Subclasses int for use as dates.'''
def __init__(self, ordinal):
int.__init__(self, ordinal)
self.__date = datetime.date.fromtimestamp(ordinal)
day = property(fget=lambda self:self.__date.day)
month = property(fget=lambda self:self.__date.month)
year = property(fget=lambda self:self.__date.year)
def isoformat(self): return self.__date.isoformat()
def timetuple(self): return self.__date.timetuple()
def date(self): return self.__date
def epoch(x):
'convert userland datetime instance x to epoch'
return time.mktime(x.timetuple())
def date(year, month, day):
return intdate(epoch(datetime.date(year, month, day)))
def today():
return intdate(epoch(datetime.date.today()))
from matplotlib.ticker import MinuteLocator, DateFormatter
from matplotlib.matlab import *
# simulate collecting data every minute starting at midnight
t0 = date(2004,04,27)
t = t0+arange(0, 2*3600, 60) # 2 hours sampled every 2 minute
s = rand(len(t))
ax = subplot(111)
ax.xaxis.set_major_locator( MinuteLocator(20) )
ax.xaxis.set_major_formatter( DateFormatter('%H:%M') )
ax.bar(t, s, width=60)
savefig('test')
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.