Hi,
It seems that the autofmt_xdate helper method is broken when twinx is
used. Consider the script below:
-----------------------------------------
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import date2num
strt = dt.datetime(2000, 3, 15, 6)
delta = dt.timedelta(hours=6)
date_list = [(strt + i*delta) for i in range(100)]
x = date2num(date_list)
y = np.sin(x)
z = np.cos(x)
fig, ax1 = plt.subplots()
ax1.plot(date_list, y, 'b-')
ax2 = ax1.twinx()
ax2.plot(date_list, z, 'r-')
# using the auto format method doesn't work
fig.autofmt_xdate()
plt.show()
-----------------------------------------
This is because the 'is_last_row' attribute isn't present on ax2 and
len(fig.axes) != 1 when the autofmt_xdate method is called on fig.
The attached patch fixes it for me and still seems to give the
advertised behaviour for single and vertically stacked subplots.
Cheers,
Scott
Index: lib/matplotlib/figure.py
===================================================================
--- lib/matplotlib/figure.py (revision 8806)
+++ lib/matplotlib/figure.py (working copy)
@@ -312,25 +312,17 @@
*ha*
the horizontal alignment of the xticklabels
"""
- allsubplots = np.alltrue([hasattr(ax, 'is_last_row') for ax in self.axes])
- if len(self.axes)==1:
- for label in ax.get_xticklabels():
- label.set_ha(ha)
- label.set_rotation(rotation)
- else:
- if allsubplots:
- for ax in self.get_axes():
- if ax.is_last_row():
- for label in ax.get_xticklabels():
- label.set_ha(ha)
- label.set_rotation(rotation)
- else:
- for label in ax.get_xticklabels():
- label.set_visible(False)
- ax.set_xlabel('')
+ for ax in self.get_axes():
+ if hasattr(ax, 'is_last_row') and ax.is_last_row():
+ for label in ax.get_xticklabels():
+ label.set_ha(ha)
+ label.set_rotation(rotation)
+ else:
+ for label in ax.get_xticklabels():
+ label.set_visible(False)
+ ax.set_xlabel('')
- if allsubplots:
- self.subplots_adjust(bottom=bottom)
+ self.subplots_adjust(bottom=bottom)
def get_children(self):
'get a list of artists contained in the figure'
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel