10000 Merge pull request #16636 from anntzer/autofmtxdate_major · matplotlib/matplotlib@50242cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 50242cf

Browse files
authored
Merge pull request #16636 from anntzer/autofmtxdate_major
Deprecate autofmt_xdate(which=None) to mean which="major".
2 parents d492a65 + e53eedb commit 50242cf

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
@@ -295,3 +295,7 @@ is deprecated, set the offset to 0 instead.
295295
``RendererCairo.fontweights``, ``RendererCairo.fontangles``
296296
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297297
... are deprecated.
298+
299+
``autofmt_xdate(which=None)``
300+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301+
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
@@ -573,7 +573,8 @@ def get_constrained_layout_pads(self, relative=False):
573573

574574
return w_pad, h_pad, wspace, hspace
575575

576-
def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
576+
def autofmt_xdate(
577+
self, bottom=0.2, rotation=30, ha='right', which='major'):
577578
"""
578579
Date ticklabels often overlap, so it is useful to rotate them
579580
and right align them. Also, a common use case is a number of
@@ -585,18 +586,19 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None):
585586
Parameters
586587
----------
587588
bottom : scalar
588-
The bottom of the subplots for :meth:`subplots_adjust`.
589-
589+
The bottom of the subplots for `subplots_adjust`.
590590
rotation : angle in degrees
591591
The rotation of the xtick labels.
592-
593592
ha : str
594593
The horizontal alignment of the xticklabels.
595-
596-
which : {None, 'major', 'minor', 'both'}
597-
Selects which ticklabels to rotate. Default is None which works
598-
the same as major.
594+
which : {'major', 'minor', 'both'}, default: 'major'
595+
Selects which ticklabels to rotate.
599596
"""
597+
if which is None:
598+
cbook.warn_deprecated(
599+
"3.3", message="Support for passing which=None to mean "
600+
"which='major' is deprecated since %(since)s and will be "
601+
"removed %(removal)s.")
600602
allsubplots = all(hasattr(ax, 'is_last_row') for ax in self.axes)
601603
if len(self.axes) == 1:
602604
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