From e53eedb4f40fbb84ace2e5b0ea72010c7581b585 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 3 Mar 2020 00:15:22 +0100 Subject: [PATCH] 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... --- doc/api/next_api_changes/deprecations.rst | 4 ++++ lib/matplotlib/figure.py | 18 ++++++++++-------- lib/matplotlib/tests/test_figure.py | 8 +++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 9e1a6862d872..c66f26cca69c 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -284,3 +284,7 @@ is deprecated, set the offset to 0 instead. ``RendererCairo.fontweights``, ``RendererCairo.fontangles`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... are deprecated. + +``autofmt_xdate(which=None)`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This is deprecated, use its more explicit synonym, ``which="major"``, instead. diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 2f9d2142b789..9bd9a35a5847 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -574,7 +574,8 @@ def get_constrained_layout_pads(self, relative=False): return w_pad, h_pad, wspace, hspace - def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right', which=None): + def autofmt_xdate( + self, bottom=0.2, rotation=30, ha='right', which='major'): """ Date ticklabels often overlap, so it is useful to rotate them 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): Parameters ---------- bottom : scalar - The bottom of the subplots for :meth:`subplots_adjust`. - + The bottom of the subplots for `subplots_adjust`. rotation : angle in degrees The rotation of the xtick labels. - ha : str The horizontal alignment of the xticklabels. - - which : {None, 'major', 'minor', 'both'} - Selects which ticklabels to rotate. Default is None which works - the same as major. + which : {'major', 'minor', 'both'}, default: 'major' + Selects which ticklabels to rotate. """ + if which is None: + cbook.warn_deprecated( + "3.3", message="Support for passing which=None to mean " + "which='major' is deprecated since %(since)s and will be " + "removed %(removal)s.") allsubplots = all(hasattr(ax, 'is_last_row') for ax in self.axes) if len(self.axes) == 1: for label in self.axes[0].get_xticklabels(which=which): diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 3586f7457f59..f1a8bc15cd6d 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -2,6 +2,10 @@ from pathlib import Path import platform import warnings +try: + from contextlib import nullcontext +except ImportError: + from contextlib import ExitStack as nullcontext # Py3.6 import matplotlib as mpl from matplotlib import rcParams @@ -318,7 +322,9 @@ def test_autofmt_xdate(which): 'FixedFormatter should only be used together with FixedLocator') ax.xaxis.set_minor_formatter(FixedFormatter(minors)) - fig.autofmt_xdate(0.2, angle, 'right', which) + with (pytest.warns(mpl.MatplotlibDeprecationWarning) if which is None else + nullcontext()): + fig.autofmt_xdate(0.2, angle, 'right', which) if which in ('both', 'major', None): for label in fig.axes[0].get_xticklabels(False, 'major'):