# 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 ...

matplotlib interprets dates as days since 0000-00-00 rather than
seconds since the epoch, so you need to convert epoch time with the
epoch2num function in matplotlib.dates and then plot with plot_dates

dnum = epoch2num(ut)
plot_date(dnum, y)

> 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").

If you are not happy with the default date ticking and formatting
provided by plot_date, you can set you own date tick locator and

and date specific tick locator and formatters here

and in the online Users Guide. See also the *date*.py examples in the
examples directory, http://matplotlib.sf.net/examples

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

Use epoch2num again

xlim(epoch2num(amin(ut)), epoch2num(amax(ut)))

Note that if you pick the appropriate date locator (which plot_date
tries to do for you automagically), you probably do not need to set
the xlim explicitly, since this is the job of the tick locator's
autoscale method.

JDH

Thanke you.

···

On Tue, Dec 13, 2005 at 09:39:57PM -0600, John Hunter wrote:

Use epoch2num again

xlim(epoch2num(amin(ut)), epoch2num(amax(ut)))

--
JP