But report: Date axis formatter problem

Problem: The autodatelocator and autodateformatter don’t seem to work properly. One, the formatter doesn’t seem to work immediately after being applied to an axis. A manual call to the locator seems necessary. Two, the autodatelocator doesn’t seem to be able to handle view intervals less than 1 second, i.e., the tick labels don’t show digits beyond second. You can see this by zooming the example figure from the code below to a level shorter than one second.

  1. Operating system: OS X 10.8.2

  2. matplotlib version: 1.2.0rc2

  3. I installed matplotlib via:

pip install git+[https://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev](https://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev)
  1. Backend: TkAgg, but I don’t think the problem depends on the backend.

  2. Code:

#--------------------------------- code -----------------------------------------------------

Running in ipython --pylab mode.

fig = figure()

tsta = num2epoch(date2num(datetime.datetime.now()))

tarr = tsta + arange(0, 60*30., 0.01) # half hour, dt = 0.01 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() # Show an overall view of the data

locator = mpl.dates.AutoDateLocator()

formatter = mpl.dates.AutoDateFormatter(locator)

formatter.scaled = {

365.0 : ‘%Y’,

  1. : ‘%b %Y’,

1.0 : ‘%b %d’,

1./24. : ‘%H:%M’,

1./24./60. : ‘%M:%S’,

1./24./60./60. : ‘%S’,

}

ax.get_xaxis().set_major_formatter(formatter) # Won’t work immediately.

locator.set_axis(ax.xaxis) # Have to manually make this call and the one below.

locator.refresh() # Another manual call.

fig.canvas.draw()

#------------------------------------ end of code --------------------------------------------------------

Bug to the bug report: In the subject, it should be ‘Bug report’, rather than ‘But report’. Oops :frowning:

Jianbao

···

On Mon, Oct 8, 2012 at 9:37 AM, Jianbao Tao <jianbao.tao@…287…> wrote:

Problem: The autodatelocator and autodateformatter don’t seem to work properly. One, the formatter doesn’t seem to work immediately after being applied to an axis. A manual call to the locator seems necessary. Two, the autodatelocator doesn’t seem to be able to handle view intervals less than 1 second, i.e., the tick labels don’t show digits beyond second. You can see this by zooming the example figure from the code below to a level shorter than one second.

  1. Operating system: OS X 10.8.2
  2. matplotlib version: 1.2.0rc2
  1. I installed matplotlib via:
pip install git+[https://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev](https://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev)
  1. Backend: TkAgg, but I don’t think the problem depends on the backend.
  1. Code:

#--------------------------------- code -----------------------------------------------------

Running in ipython --pylab mode.

fig = figure()

tsta = num2epoch(date2num(datetime.datetime.now()))

tarr = tsta + arange(0, 60*30., 0.01) # half hour, dt = 0.01 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() # Show an overall view of the data

locator = mpl.dates.AutoDateLocator()

formatter = mpl.dates.AutoDateFormatter(locator)

formatter.scaled = {

365.0 : ‘%Y’,

  1. : ‘%b %Y’,

1.0 : ‘%b %d’,

1./24. : ‘%H:%M’,

1./24./60. : ‘%M:%S’,

1./24./60./60. : ‘%S’,

}

ax.get_xaxis().set_major_formatter(formatter) # Won’t work immediately.

locator.set_axis(ax.xaxis) # Have to manually make this call and the one below.

locator.refresh() # Another manual call.

fig.canvas.draw()

#------------------------------------ end of code --------------------------------------------------------

I put it on github: https://github.com/matplotlib/matplotlib/issues/1343

···

On Mon, Oct 8, 2012 at 4:37 PM, Jianbao Tao <jianbao.tao@...287...> wrote:

Problem: The autodatelocator and autodateformatter don't seem to work
properly. One, the formatter doesn't seem to work immediately after being
applied to an axis. A manual call to the locator seems necessary. Two, the
autodatelocator doesn't seem to be able to handle view intervals less than 1
second, i.e., the tick labels don't show digits beyond second. You can see
this by zooming the example figure from the code below to a level shorter
than one second.

1. Operating system: OS X 10.8.2
2. matplotlib version: 1.2.0rc2
3. I installed matplotlib via:

pip install
git+https://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev

4. Backend: TkAgg, but I don't think the problem depends on the backend.
5. Code:
#--------------------------------- code
-----------------------------------------------------
# Running in ipython --pylab mode.
fig = figure()
tsta = num2epoch(date2num(datetime.datetime.now()))
tarr = tsta + arange(0, 60*30., 0.01) # half hour, dt = 0.01 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() # Show an overall view of the data

locator = mpl.dates.AutoDateLocator()
formatter = mpl.dates.AutoDateFormatter(locator)

formatter.scaled = {
    365.0 : '%Y',
    30. : '%b %Y',
    1.0 : '%b %d',
    1./24. : '%H:%M',
    1./24./60. : '%M:%S',
    1./24./60./60. : '%S',
}
ax.get_xaxis().set_major_formatter(formatter) # Won't work immediately.
locator.set_axis(ax.xaxis) # Have to manually make this call and the one
below.
locator.refresh() # Another manual call.
fig.canvas.draw()
#------------------------------------ end of code
--------------------------------------------------------

--
Damon McDougall
http://www.damon-is-a-geek.com
B2.39
Mathematics Institute
University of Warwick
Coventry
West Midlands
CV4 7AL
United Kingdom