Skip to content

Deprecate autofmt_xdate(which=None) to mean which="major". #16636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 10 additions & 8 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down