8000 Deprecate autofmt_xdate(which=None) to mean which="major". · matplotlib/matplotlib@d5795c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5795c9

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 76c764c commit d5795c9

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
@@ -242,3 +242,7 @@ The following related APIs are also deprecated:
242242
``matplotlib.test(recursionlimit=...)``
243243
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244244
The *recursionlimit* parameter of ``matplotlib.test`` is deprecated.
245+
246+
``autofmt_xdate(which=None)``
247+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248+
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
@@ -579,7 +579,8 @@ def get_constrained_layout_pads(self, relative=False):
579579

580580
return w_pad, h_pad, wspace, hspace
581581

582-
def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
582+
def autofmt_xdate(
583+
self, bottom=0.2, rotation=30, ha='right', which='major'):
583584
"""
584585
Date ticklabels often overlap, so it is useful to rotate them
585586
and right align them. Also, a common use case is a number of
@@ -591,18 +592,19 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
591592
Parameters
592593
----------
593594
bottom : scalar
594-
The bottom of the subplots for :meth:`subplots_adjust`.
595-
595+
The bottom of the subplots for `subplots_adjust`.
596596
rotation : angle in degrees
597597
The rotation of the xtick labels.
598-
599598
ha : str
600599
The horizontal alignment of the xticklabels.
601-
602-
which : {None, 'major', 'minor', 'both'}
603-
Selects which ticklabels to rotate. Default is None which works
604-
the same as major.
600+
which : {'major', 'minor', 'both'}, default: 'major'
601+
Selects which ticklabels to rotate.
605602
"""
603+
if which is None:
604+
cbook.warn_deprecated(
605+
"3.3", message="Support for passing which=None to mean "
606+
"which='major' is deprecated since %(since)s and will be "
607+
"removed %(removal)s.")
606608
allsubplots = all(hasattr(ax, 'is_last_row') for ax in self.axes)
607609
if len(self.axes) == 1:
608610
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)
0