MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / autofmt_xdate

Method autofmt_xdate

lib/matplotlib/figure.py:175–218  ·  view source on GitHub ↗

Date ticklabels often overlap, so it is useful to rotate them and right align them. Also, a common use case is a number of subplots with shared x-axis where the x-axis is date data. The ticklabels are often long, and it helps to rotate them on the bottom su

(
            self, bottom=0.2, rotation=30, ha='right', which='major')

Source from the content-addressed store, hash-verified

173 return artists
174
175 def autofmt_xdate(
176 self, bottom=0.2, rotation=30, ha='right', which='major'):
177 """
178 Date ticklabels often overlap, so it is useful to rotate them
179 and right align them. Also, a common use case is a number of
180 subplots with shared x-axis where the x-axis is date data. The
181 ticklabels are often long, and it helps to rotate them on the
182 bottom subplot and turn them off on other subplots, as well as
183 turn off xlabels.
184
185 Parameters
186 ----------
187 bottom : float, default: 0.2
188 The bottom of the subplots for `subplots_adjust`.
189 rotation : float, default: 30 degrees
190 The rotation angle of the xtick labels in degrees.
191 ha : {'left', 'center', 'right'}, default: 'right'
192 The horizontal alignment of the xticklabels.
193 which : {'major', 'minor', 'both'}, default: 'major'
194 Selects which ticklabels to rotate.
195 """
196 _api.check_in_list(['major', 'minor', 'both'], which=which)
197 axes = [ax for ax in self.axes if ax._label != '<colorbar>']
198 allsubplots = all(ax.get_subplotspec() for ax in axes)
199 if len(axes) == 1:
200 for label in self.axes[0].get_xticklabels(which=which):
201 label.set_ha(ha)
202 label.set_rotation(rotation)
203 else:
204 if allsubplots:
205 for ax in axes:
206 if ax.get_subplotspec().is_last_row():
207 for label in ax.get_xticklabels(which=which):
208 label.set_ha(ha)
209 label.set_rotation(rotation)
210 else:
211 for label in ax.get_xticklabels(which=which):
212 label.set_visible(False)
213 ax.set_xlabel('')
214
215 engine = self.get_layout_engine()
216 if allsubplots and (engine is None or engine.adjust_compatible):
217 self.subplots_adjust(bottom=bottom)
218 self.stale = True
219
220 def get_children(self):
221 """Get a list of artists contained in the figure."""

Callers 9

test_date_axvspanFunction · 0.80
test_date_axvlineFunction · 0.80
test_RRuleLocatorFunction · 0.80
test_DateFormatterFunction · 0.80
test_fill_unitsFunction · 0.80
test_autofmt_xdateFunction · 0.80

Calls 7

subplots_adjustMethod · 0.95
set_rotationMethod · 0.80
is_last_rowMethod · 0.80
set_xlabelMethod · 0.80
get_subplotspecMethod · 0.45
set_visibleMethod · 0.45
get_layout_engineMethod · 0.45

Tested by 7

test_date_axvspanFunction · 0.64
test_date_axvlineFunction · 0.64
test_RRuleLocatorFunction · 0.64
test_DateFormatterFunction · 0.64
test_fill_unitsFunction · 0.64
test_autofmt_xdateFunction · 0.64