histogram of evetns, unix time

Hallo,

I have array (ut) of numbers represents unix time (number of seconds
from 1. 1. 1970) of some evenets:

    ...
    1127164705
    1127199439
    1127199439
    1127199494
    1127199640
    1127199651
    ...

I want to plot histogram of this events. I used:

    from pylab import *
    n, bins, patches = hist( ut, 50 )
    setp(patches, 'facecolor', 'g', 'alpha', 0.75)
    axis([ 0.9999*amin(ut), 1.0001*amax(ut), 0, 1.1*amax(n) ])
    show()

But I want to display labels on x-axis's tics as a date human readable
date (for example "Dec 13").

Can anybody help me?

···

--
JP

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()

It works perfectly. Thanke you.

How can I set x-axis range? In case of my real data the histogram is not
"centred" and epmty spaces was too huge. In my previous way works:

    axis([ 0.9999*amin(ut), 1.0001*amax(ut), 0, 1.1*amax(n) ])

···

--
JP