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

Skip to content

Commit 73e44cc

Browse files
committed
Also templatize x/y/zaxis_date.
1 parent 5350e8a commit 73e44cc

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import OrderedDict
22
from contextlib import ExitStack
33
import functools
4+
import inspect
45
import itertools
56
import logging
67
import math
@@ -44,7 +45,8 @@ def _axis_method_wrapper(attr_name, method_name, *, doc_sub=None):
4445
4546
The docstring of ``get_foo`` is built by replacing "this Axis" by "the
4647
{attr_name}" ("the xaxis", "the yaxis") in the wrapped method's docstring;
47-
additional replacements can by given in *doc_sub*.
48+
additional replacements can by given in *doc_sub*. The docstring is also
49+
dedented to simplify further manipulations.
4850
"""
4951

5052
method = getattr(maxis.Axis, method_name)
@@ -62,7 +64,7 @@ def wrapper(self, *args, **kwargs):
6264
(f"The docstring of wrapped Axis method {method_name!r} must "
6365
f"contain {k!r} as a substring.")
6466
doc = doc.replace(k, v)
65-
wrapper.__doc__ = doc
67+
wrapper.__doc__ = inspect.cleandoc(doc)
6668

6769
return wrapper
6870

@@ -3635,29 +3637,8 @@ def set_yscale(self, value, **kwargs):
36353637
"yaxis", "_set_ticklabels",
36363638
doc_sub={"Axis.set_ticks": "Axes.set_yticks"})
36373639

3638-
def xaxis_date(self, tz=None):
3639-
"""
3640-
Sets up x-axis ticks and labels that treat the x data as dates.
3641-
3642-
Parameters
3643-
----------
3644-
tz : str or `datetime.tzinfo`, default: :rc:`timezone`
3645-
Timezone.
3646-
"""
3647-
# should be enough to inform the unit conversion interface
3648-
# dates are coming in
3649-
self.xaxis.axis_date(tz)
3650-
3651-
def yaxis_date(self, tz=None):
3652-
"""
3653-
Sets up y-axis ticks and labels that treat the y data as dates.
3654-
3655-
Parameters
3656-
----------
3657-
tz : str or `datetime.tzinfo`, default: :rc:`timezone`
3658-
Timezone.
3659-
"""
3660-
self.yaxis.axis_date(tz)
3640+
xaxis_date = _axis_method_wrapper("xaxis", "axis_date")
3641+
yaxis_date = _axis_method_wrapper("yaxis", "axis_date")
36613642

36623643
def format_xdata(self, x):
36633644
"""

lib/matplotlib/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,11 +1752,11 @@ def zoom(self, direction):
17521752

17531753
def axis_date(self, tz=None):
17541754
"""
1755-
Sets up axis ticks and labels treating data along this axis as dates.
1755+
Sets up axis ticks and labels to treat data along this Axis as dates.
17561756
17571757
Parameters
17581758
----------
1759-
tz : tzinfo or str or None
1759+
tz : str or `datetime.tzinfo`, default: :rc:`timezone`
17601760
The timezone used to create date labels.
17611761
"""
17621762
# By providing a sample datetime instance with the desired timezone,

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from collections import defaultdict
1414
from functools import reduce
1515
import math
16+
import textwrap
1617

1718
import numpy as np
1819

@@ -830,23 +831,15 @@ def set_zscale(self, value, **kwargs):
830831
"zaxis", "_set_ticklabels",
831832
doc_sub={"Axis.set_ticks": "Axes.set_zticks"})
832833

833-
def zaxis_date(self, tz=None):
834-
"""
835-
Sets up z-axis ticks and labels that treat the z data as dates.
836-
837-
.. note::
838-
This function is merely provided for completeness.
839-
Axes3D objects do not officially support dates for ticks,
840-
and so this may or may not work as expected.
841-
842-
.. versionadded:: 1.1.0
843-
This function was added, but not tested. Please report any bugs.
834+
zaxis_date = _axis_method_wrapper("zaxis", "axis_date")
835+
if zaxis_date.__doc__:
836+
zaxis_date.__doc__ += textwrap.dedent("""
844837
845-
Parameters
846-
----------
847-
tz : `datetime.tzinfo`, default: :rc:`timezone`
848-
"""
849-
self.zaxis.axis_date(tz)
838+
Notes
839+
-----
840+
This function is merely provided for completeness, but 3d axes do not
841+
support dates for ticks, and so this may not work as expected.
842+
""")
850843

851844
def clabel(self, *args, **kwargs):
852845
"""

0 commit comments

Comments
 (0)