@@ -164,11 +164,13 @@ def __init__(self,
164164
165165 def autofmt_xdate (self , bottom = 0.2 , rotation = 30 , ha = 'right' ):
166166 """
167- A common use case is a number of subplots with shared xaxes
168- where the x-axis is date data. The ticklabels are often
169- long,and it helps to rotate them on the bottom subplot and
170- turn them off on other subplots. This function will raise a
171- RuntimeError if any of the Axes are not Subplots.
167+ Date ticklabels often overlap, so it is useful to rotate them
168+ and right align them. Also, a common use case is a number of
169+ subplots with shared xaxes where the x-axis is date data. The
170+ ticklabels are often long, and it helps to rotate them on the
171+ bottom subplot and turn them off on other subplots, as well as
172+ turn off xlabels.
173+
172174
173175 bottom : the bottom of the subplots for subplots_adjust
174176 rotation: the rotation of the xtick labels
@@ -177,17 +179,25 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'):
177179
178180 """
179181
180- for ax in self .get_axes ():
181- if not hasattr (ax , 'is_last_row' ):
182- raise RuntimeError ('Axes must be subplot instances; found %s' % type (ax ))
183- if ax .is_last_row ():
184- for label in ax .get_xticklabels ():
185- label .set_ha (ha )
186- label .set_rotation (rotation )
187- else :
188- for label in ax .get_xticklabels ():
189- label .set_visible (False )
190- self .subplots_adjust (bottom = bottom )
182+ allsubplots = npy .alltrue ([hasattr (ax , 'is_last_row' ) for ax in self .axes ])
183+ if len (self .axes )== 1 :
184+ for label in ax .get_xticklabels ():
185+ label .set_ha (ha )
186+ label .set_rotation (rotation )
187+ else :
188+ if allsubplots :
189+ for ax in self .get_axes ():
190+ if ax .is_last_row ():
191+ for label in ax .get_xticklabels ():
192+ label .set_ha (ha )
193+ label .set_rotation (rotation )
194+ else :
195+ for label in ax .get_xticklabels ():
196+ label .set_visible (False )
197+ ax .set_xlabel ('' )
198+
199+ if allsubplots :
200+ self .subplots_adjust (bottom = bottom )
191201
192202 def get_children (self ):
193203 'get a list of artists contained in the figure'
0 commit comments