Transforms for collections on date axes

I raised this a week or so ago on mpl-users, and after some more
digging I thought I'd bring it over to mpl-dev.

With the following snippet, I expect a vertical Line2D from y=(0, 2)
and a Collection of squares at y=(4, 5, 6) at the specified time.

The actual result is a vertical line and no squares, even though the y
axis limits adjust to (0,7) as if something is being plotted with the
call to scatter.

from pylab import *
from datetime import datetime
f=figure()
ax=f.add_subplot(111)
d=datetime(2004,05,26,23,00,00)
d=date2num(d)
ax.xaxis_date()
ln, = ax.plot((d,d,d),range(3)) # vertical line
sc = ax.scatter((d,d,d),(4,5,6),marker='s') # no symbols plotted
show()

However, with ax.xaxis_date() just before show(), I see the Collection.

What is the cause of this inconsistency? I was surprised by it, since
I naively assumed that once the axis property was set, future
additions to the axes would plot with the date axis in mind, as Line2D
seems to. I poked around a bit with the _transform, _transforms, and
_transOffset properties of the collections, but didn't get anywhere.

I'll be using date axes heavily in an interactive MPL project, where
it would be nice to set the date axes once and forget about it. I'm
willing to work on a fix if the problem is more than a lack
understanding on my end.

Thanks,
Eric

Eric Bruning wrote:

I raised this a week or so ago on mpl-users, and after some more
digging I thought I'd bring it over to mpl-dev.

With the following snippet, I expect a vertical Line2D from y=(0, 2)
and a Collection of squares at y=(4, 5, 6) at the specified time.

The actual result is a vertical line and no squares, even though the y
axis limits adjust to (0,7) as if something is being plotted with the
call to scatter.

from pylab import *
from datetime import datetime
f=figure()
ax=f.add_subplot(111)
d=datetime(2004,05,26,23,00,00)
d=date2num(d)
ax.xaxis_date()
ln, = ax.plot((d,d,d),range(3)) # vertical line
sc = ax.scatter((d,d,d),(4,5,6),marker='s') # no symbols plotted
show()

However, with ax.xaxis_date() just before show(), I see the Collection.

What is the cause of this inconsistency? I was surprised by it, since
I naively assumed that once the axis property was set, future
additions to the axes would plot with the date axis in mind, as Line2D
seems to. I poked around a bit with the _transform, _transforms, and
_transOffset properties of the collections, but didn't get anywhere.

I'll be using date axes heavily in an interactive MPL project, where
it would be nice to set the date axes once and forget about it. I'm
willing to work on a fix if the problem is more than a lack
understanding on my end.

Thanks,
Eric

Eric,

I think most of us on the development side are a bit confused about the "units" support that handles dates among other things. In particular, a few days ago I was checking scatter and found that it did not work with dates (at least not in the simplest example). I fixed one thing that looked like it might have been causing the trouble, but it still didn't work. John has promised to provide some guidance, and so I hope we soon can make units work everywhere they should, and make it clear from the docstrings when they can or can't be used.

Eric