Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e53eedb

Browse files
committed
Deprecate autofmt_xdate(which=None) to mean which="major".
This makes the docstring and signature simpler, and explicitly passing which=None to mean which="major" just seems wicked...
1 parent d7ba944 commit e53eedb

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,7 @@ is deprecated, set the offset to 0 instead.
284284
``RendererCairo.fontweights``, ``RendererCairo.fontangles``
285285
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
286286
... are deprecated.
287+
288+
``autofmt_xdate(which=None)``
289+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290+
This is deprecated, use its more explicit synonym, ``which="major"``, instead.

lib/matplotlib/figure.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ def get_constrained_layout_pads(self, relative=False):
574574

575575
return w_pad, h_pad, wspace, hspace
576576

577-
def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
577+
def autofmt_xdate(
578+
self, bottom=0.2, rotation=30, ha='right', which='major'):
578579
"""
579580
Date ticklabels often overlap, so it is useful to rotate them
580581
and right align them. Also, a common use case is a number of
@@ -586,18 +587,19 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
586587
Parameters
587588
----------
588589
bottom : scalar
589-
The bottom of the subplots for :meth:`subplots_adjust`.
590-
590+
The bottom of the subplots for `subplots_adjust`.
591591
rotation : angle in degrees
592592
The rotation of the xtick labels.
593-
594593
ha : str
595594
The horizontal alignment of the xticklabels.
596-
597-
which : {None, 'major', 'minor', 'both'}
598-
Selects which ticklabels to rotate. Default is None which works
599-
the same as major.
595+
which : {'major', 'minor', 'both'}, default: 'major'
596+
Selects which ticklabels to rotate.
600597
"""
598+
if which is None:
599+
cbook.warn_deprecated(
600+
"3.3", message="Support for passing which=None to mean "
601+
"which='major' is deprecated since %(since)s and will be "
602+
"removed %(removal)s.")
601603
allsubplots = all(hasattr(ax, 'is_last_row') for ax in self.axes)
602604
if len(self.axes) == 1:
603605
for label in self.axes[0].get_xticklabels(which=which):

lib/matplotlib/tests/test_figure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from pathlib import Path
33
import platform
44
import warnings
5+
try:
6+
from contextlib import nullcontext
7+
except ImportError:
8+
from contextlib import ExitStack as nullcontext # Py3.6
59

610
import matplotlib as mpl
711
from matplotlib import rcParams
@@ -318,7 +322,9 @@ def test_autofmt_xdate(which):
318322
'FixedFormatter should only be used together with FixedLocator')
319323
ax.xaxis.set_minor_formatter(FixedFormatter(minors))
320324

321-
fig.autofmt_xdate(0.2, angle, 'right', which)
325+
with (pytest.warns(mpl.MatplotlibDeprecationWarning) if which is None else
326+
nullcontext()):
327+
fig.autofmt_xdate(0.2, angle, 'right', which)
322328

323329
if which in ('both', 'major', None):
324330
for label in fig.axes[0].get_xticklabels(False, 'major'):

0 commit comments

Comments
 (0)