|
From: Benjamin R. <ben...@ou...> - 2012-10-08 13:17:15
|
On Sun, Oct 7, 2012 at 6:47 PM, Jianbao Tao <jia...@gm...> wrote:
> fig = figure()
> tsta = num2epoch(date2num(datetime.datetime.now()))
> tarr = tsta + arange(0, 60*60*0.5, 0.1) # half hour, dt =
> 0.1 sec
> x = np.array(num2date(epoch2num(tarr)))
> nt = len(tarr)
> y = randn(nt)
>
> ax = fig.add_subplot(111)
> ax.plot(x, y)
> fig.canvas.draw()
>
> # Make a formatter instance.
> locator = mpl.dates.AutoDateLocator()
> formatter = mpl.dates.AutoDateFormatter(locator)
>
> # Customize the scaling.
> formatter.scaled = {
> 365.0 : '%Y', # view interval > 356 days
> 30. : '%b %Y', # view interval > 30 days but less than 365
> days
> 1.0 : '%b %d', # view interval > 1 day but less than 30
> days
> 1./24. : '%H:%M', # view interval > 1 hour but less than 24
> hours
> 1./24./60. : '%M:%S', # view interval > 1 min but less than 1 hour
> 1./24./60./60. : '%S', # view interval < 1 min
> }
>
> # Apply the formatter and redraw the plot.
> ax.get_xaxis().set_major_formatter(formatter)
> fig.canvas.draw()
>
Confirmed. It seems like that code fell out of maintenance a bit somehow.
Luckily, there is a quick fix to get your code working again. Just add the
following two lines after you set the major formatter, but before your
final draw:
locator.set_axis(ax.xaxis)
locator.refresh()
Note, if you zoom in and out after that call, I doubt it will re-adjust
your formatter. Could you file a bug report, please?
Cheers!
Ben Root
|