Date axis cannot be reversed ?

I am using matplotlib 0.84 on OS X 10.3.9, Agg backend.

The way in which I reverse axes ( axis values getting smaller going left to right or bottom to top) uses the following code:

ax = subplot(111)
..
xLim = ax.get_xlim()
ax.set_xlim( (xLim[1],xLim[0]))
.
I do not know if this is the best way - but it has worked up to now.

If I try to use this method on an axis that uses dates, the method fails in that no tick labels are generated.
The actual plot is flipped around but there are no tick labels.

In the code below I have attempted to flip the x-axis in the date_demo2.py from the examples directory.
I have added lines 36-37.
I get the following traceback:

Traceback (most recent call last):
   File "_tmp_date_demo2.py", line 46, in ?
     setp(labels, rotation=45)
   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/matplotlib/pylab.py", line 1533, in setp
     ret = _setp(*args, **kwargs)
   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/matplotlib/artist.py", line 468, in setp
     insp = ArtistInspector(h)
   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/matplotlib/artist.py", line 260, in __init__
     if iterable(o): o = o[0]
IndexError: list index out of range

However if I comment out the lines which rotate the x labels, the code runs but the resulting plot has no x (date) labels.

Thanks for any help.
--Jim

date_demo2.py
#!/usr/bin/env python
"""
Show how to make date plots in matplotlib using date tick locators and
formatters. See major_minor_demo1.py for more information on
controlling major and minor ticks
"""
import datetime
from pylab import *
from matplotlib.dates import MONDAY, SATURDAY
from matplotlib.finance import quotes_historical_yahoo
from matplotlib.dates import MonthLocator, WeekdayLocator, DateFormatter

date1 = datetime.date( 2002, 1, 5 )
date2 = datetime.date( 2003, 12, 1 )

mondays = WeekdayLocator(MONDAY) # every monday
months = MonthLocator(range(1,13), bymonthday=1) # every month
monthsFmt = DateFormatter("%b '%y")

quotes = quotes_historical_yahoo('INTC', date1, date2)
if not quotes:
     print 'Found no quotes'
     raise SystemExit

dates = [q[0] for q in quotes]
opens = [q[1] for q in quotes]

ax = subplot(111)
plot_date(dates, opens, '-')
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(mondays)
ax.autoscale_view()
xLim = ax.get_xlim()
ax.set_xlim( (xLim[1],xLim[0]))
#ax.xaxis.grid(False, 'major')
#ax.xaxis.grid(True, 'minor')

labels = ax.get_xticklabels()
setp(labels, rotation=45)

grid(True)
savefig('date_demo2')

I think you've ran into the same problem Vinj Vinj had a little while ago:

  http://sourceforge.net/mailarchive/message.php?msg_id=14103209

John Hunter recommended the following solution:

  http://sourceforge.net/mailarchive/message.php?msg_id=14107408

I'm not sure if you'll need to watch out for this, but Alan Isaac cautioned that this fix may not work correctly under Python 2.4:

  http://sourceforge.net/mailarchive/message.php?msg_id=14108794

I hope this helps!

Ken

···

On 12/16/05 10:56, James Boyle wrote:

I get the following traceback:

Traceback (most recent call last):
  File "_tmp_date_demo2.py", line 46, in ?
    setp(labels, rotation=45)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/matplotlib/pylab.py", line 1533, in setp
    ret = _setp(*args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/matplotlib/artist.py", line 468, in setp
    insp = ArtistInspector(h)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/matplotlib/artist.py", line 260, in __init__
    if iterable(o): o = o[0]
IndexError: list index out of range

Ken - Thanks very much or the quick reply - but the problem is more fundamental:

I probably obscured the issue by including the traceback.
The label rotation fails because there are no labels - the index is out of range - but circumventing this error still results in a plot with no x tick labels.
At the bottom of my original message, I indicated that commenting out the rotation enables the code to run to completion but no date labels are generated.

--Jim

···

On Dec 16, 2005, at 9:14 AM, Ken McIvor wrote:

On 12/16/05 10:56, James Boyle wrote:

I get the following traceback:
Traceback (most recent call last):
  File "_tmp_date_demo2.py", line 46, in ?
    setp(labels, rotation=45)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/matplotlib/pylab.py", line 1533, in setp
    ret = _setp(*args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/matplotlib/artist.py", line 468, in setp
    insp = ArtistInspector(h)
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/matplotlib/artist.py", line 260, in __init__
    if iterable(o): o = o[0]
IndexError: list index out of range

I think you've ran into the same problem Vinj Vinj had a little while ago:

  http://sourceforge.net/mailarchive/message.php?msg_id=14103209

John Hunter recommended the following solution:

  http://sourceforge.net/mailarchive/message.php?msg_id=14107408

I'm not sure if you'll need to watch out for this, but Alan Isaac cautioned that this fix may not work correctly under Python 2.4:

  http://sourceforge.net/mailarchive/message.php?msg_id=14108794

I hope this helps!

Ken

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users