|
From: <rom...@ya...> - 2005-12-13 18:20:47
|
Jiri Polcar wrote:
>
> But I want to display labels on x-axis's tics as a date human readable
> date (for example "Dec 13").
>
I adapted this from finance_demo.py. You will probably have to adjust it
to better suit your needs. It assumes the ut array is sorted.
from pylab import *
from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \
DayLocator, MONDAY, timezone
import time,datetime
ut = [1127164705, 1127199439, 1127199439, 1127199494, 1127199640,
1127199651]
date1 = apply(datetime.date,time.localtime(ut[0])[0:3])
date2 = apply(datetime.date,time.localtime(ut[-1])[0:3])
mondays = WeekdayLocator(MONDAY)
weekFormatter = DateFormatter('%b %d') # Eg, Jan 12
alldays = DayLocator()
ax = subplot(111)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)
dates = []
for u in ut:
year,month,day = time.localtime(u)[0:3]
dates.append(datetime.date(year,month,day).toordinal())
n, bins, patches = hist( dates, 50 )
setp(patches, 'facecolor', 'g', 'alpha', 0.75)
#axis([ 0.9999*amin(ut), 1.0001*amax(ut), 0, 1.1*amax(n) ])
show()
|