|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | -import matplotlib |
4 | | -#matplotlib.use('TkAgg') |
5 | | -from matplotlib import pylab |
6 | | -PL = pylab |
7 | | -from matplotlib.dates import DayLocator, HourLocator, \ |
8 | | - drange, date2num, timezone |
9 | 3 | import datetime |
| 4 | +from pylab import figure, show, nx |
| 5 | +from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange |
10 | 6 |
|
11 | | -matplotlib.rcParams['timezone'] = 'US/Pacific' |
12 | | -tz = timezone('US/Pacific') |
13 | 7 |
|
14 | | - |
15 | | -date1 = datetime.datetime( 2000, 3, 2, tzinfo=tz) |
16 | | -date2 = datetime.datetime( 2000, 3, 6, tzinfo=tz) |
| 8 | +date1 = datetime.datetime( 2000, 3, 2) |
| 9 | +date2 = datetime.datetime( 2000, 3, 6) |
17 | 10 | delta = datetime.timedelta(hours=6) |
18 | 11 | dates = drange(date1, date2, delta) |
19 | 12 |
|
20 | | -y = PL.arange( len(dates)*1.0) |
21 | | -ysq = y*y |
22 | | - |
23 | | -# note new constructor takes days or sequence of days you want to |
24 | | -# tick, not the hour as before. Default is to tick every day |
25 | | -majorTick = DayLocator(tz=tz) |
| 13 | +y = nx.arange( len(dates)*1.0) |
26 | 14 |
|
27 | | -# the hour locator takes the hour or sequence of hours you want to |
28 | | -# tick, not the base multiple |
29 | | -minorTick = HourLocator(range(0,25,6), tz=tz) |
30 | | -ax = PL.subplot(111) |
31 | | -ax.plot_date(dates, ysq, tz=tz) |
| 15 | +fig = figure() |
| 16 | +ax = fig.add_subplot(111) |
| 17 | +ax.plot_date(dates, y*y) |
32 | 18 |
|
33 | 19 | # this is superfluous, since the autoscaler should get it right, but |
34 | 20 | # use date2num and num2date to to convert between dates and floats if |
35 | 21 | # you want; both date2num and num2date convert an instance or sequence |
36 | | -PL.xlim( dates[0], dates[-1] ) |
37 | | -ax.xaxis.set_major_locator(majorTick) |
38 | | -ax.xaxis.set_minor_locator(minorTick) |
39 | | -labels = ax.get_xticklabels() |
40 | | -PL.setp(labels,'rotation', 90) |
41 | | -PL.show() |
| 22 | +ax.set_xlim( dates[0], dates[-1] ) |
| 23 | + |
| 24 | +# The hour locator takes the hour or sequence of hours you want to |
| 25 | +# tick, not the base multiple |
| 26 | + |
| 27 | +ax.xaxis.set_major_locator( DayLocator() ) |
| 28 | +ax.xaxis.set_minor_locator( HourLocator(nx.arange(0,25,6)) ) |
| 29 | +ax.xaxis.set_major_formatter( DateFormatter('%Y-%m-%d') ) |
| 30 | + |
| 31 | +ax.fmt_xdata = DateFormatter('%Y-%m-%d %H:%M:%S') |
| 32 | +fig.autofmt_xdate() |
| 33 | + |
| 34 | +show() |
0 commit comments