This surprises me as the AutoDateFormatter automatically kicks in once you
pass through some datetime objects, and the AutoDateFormatter & Locator do
the right thing when zooming (the format changes depending on the temporal
resolution). For example, the following code behaves nicely when I zoom in
to a small segment of the line:

import datetime as dt
import numpy as np
import matplotlib.pyplot as plt


d1 = dt.datetime(1990, 1, 1)

n = 365
x = np.array([d1 + dt.timedelta(days=i) for i in range(n)], dtype=object)

y = np.sin(np.linspace(0, np.pi * 2, n))

plt.plot(x, y)

plt.show()



Are you definately passing through datetime objects, or are you passing
through the datetime "ordinals" / Julian time?

Cheers,

Phil




On 11 July 2013 16:04, Skip Montanaro <s...@pobox.com> wrote:

> > I have a small matplotlib app I wrote to plot columns of a CSV files.
> > The X axis is almost always time. Once displayed, I will often zoom in
> > on a small patch of a plot.  I'm currently selecting the strftime
> > format based on the original time range of the input.  As I zoom in,
> > however, that doesn't work so well....
>
> > but when I use it in the obvious way, all I get is the current year
> > for all tick labels, despite the fact that the scaled attribute of the
> > formatter has keys which are much smaller than a year.
>
> I kind of got this working.  I had to associate the locator with the X
> axis and call it's autoscale() method before calling plot.show().  Now
> I get %H:%M:%S formatting for everything, even when I'm zoomed way out
> on a data set containing two-days worth of time series data.  I
> suppose I can fiddle with the AutoDateFormatter's scaled attribute,
> but the default looks like it ought to work.  Any thoughts on what I'm
> (still) missing?
>
> The locator/formatter code looks like this:
>
>     locator = matplotlib.dates.AutoDateLocator()
>     formatter = matplotlib.dates.AutoDateFormatter(locator)
>     ...
>     left_plot = figure.add_subplot(111)
>     left_plot.set_title(title)
>     left_plot.set_axisbelow(True)
>     left_plot.yaxis.set_major_formatter(pylab.FormatStrFormatter('%g'))
>     ...
>     locator.set_axis(left_plot.xaxis)
>     left_plot.xaxis.set_major_formatter(formatter)
>     locator.autoscale()
>     pylab.show()
>
> This works fine except for the lack of dynamic scaling and apparently
> incorrect choice of labels on plots over large time scales.
>
> Skip
>
>
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to