30
30
_log = logging .getLogger (__name__ )
31
31
32
32
33
- def _axis_method_wrapper (attr_name , method_name ):
33
+ def _axis_method_wrapper (attr_name , method_name , * , doc_sub = None ):
34
34
"""
35
35
Helper to generate Axes methods wrapping Axis methods.
36
36
@@ -41,6 +41,10 @@ def _axis_method_wrapper(attr_name, method_name):
41
41
``get_foo`` is a method that forwards it arguments to the ``get_bar``
42
42
method of the ``xaxis`` attribute, and gets its signature and docstring
43
43
from ``Axis.get_bar``.
44
+
45
+ The docstring of ``get_foo`` is built by replacing "this Axis" by "the
46
+ {attr_name}" ("the xaxis", "the yaxis") in the wrapped method's docstring;
47
+ additional replacements can by given in *doc_sub*.
44
48
"""
45
49
46
50
method = getattr (maxis .Axis , method_name )
@@ -50,13 +54,15 @@ def _axis_method_wrapper(attr_name, method_name):
50
54
def wrapper (self , * args , ** kwargs ):
51
55
return get_method (self )(* args , ** kwargs )
52
56
53
- if wrapper .__doc__ :
54
- assert "this Axis" in wrapper .__doc__ , \
55
- (f"The docstring of wrapped Axis methods must contain "
56
- f"'this Axis' as a substring, but this is not the case for "
57
- f"{ method_name } " )
58
- wrapper .__doc__ = wrapper .__doc__ .replace (
59
- "this Axis" , f"the { attr_name } " , 1 )
57
+ doc = wrapper .__doc__
58
+ if doc :
59
+ doc_sub = {"this Axis" : f"the { attr_name } " , ** (doc_sub or {})}
60
+ for k , v in doc_sub .items ():
61
+ assert k in doc , \
62
+ (f"The docstring of wrapped Axis method { method_name !r} must "
63
+ f"contain { k !r} as a substring." )
64
+ doc = doc .replace (k , v )
65
+ wrapper .__doc__ = doc
60
66
61
67
return wrapper
62
68
@@ -3356,49 +3362,9 @@ def set_xscale(self, value, **kwargs):
3356
3362
get_xmajorticklabels = _axis_method_wrapper ("xaxis" , "get_majorticklabels" )
3357
3363
get_xminorticklabels = _axis_method_wrapper ("xaxis" , "get_minorticklabels" )
3358
3364
get_xticklabels = _axis_method_wrapper ("xaxis" , "get_ticklabels" )
3359
-
3360
- @cbook ._make_keyword_only ("3.3" , "fontdict" )
3361
- def set_xticklabels (self , labels , fontdict = None , minor = False , ** kwargs ):
3362
- """
3363
- Set the x-tick labels with list of string labels.
3364
-
3365
- .. warning::
3366
- This method should only be used after fixing the tick positions
3367
- using `~.axes.Axes.set_xticks`. Otherwise, the labels may end up
3368
- in unexpected positions.
3369
-
3370
- Parameters
3371
- ----------
3372
- labels : list of str
3373
- The label texts.
3374
-
3375
- fontdict : dict, optional
3376
- A dictionary controlling the appearance of the ticklabels.
3377
- The default *fontdict* is::
3378
-
3379
- {'fontsize': rcParams['axes.titlesize'],
3380
- 'fontweight': rcParams['axes.titleweight'],
3381
- 'verticalalignment': 'baseline',
3382
- 'horizontalalignment': loc}
3383
-
3384
- minor : bool, default: False
3385
- Whether to set the minor ticklabels rather than the major ones.
3386
-
3387
- Returns
3388
- -------
3389
- list of `~.Text`
3390
- The labels.
3391
-
3392
- Other Parameters
3393
- ----------------
3394
- **kwargs : `~.text.Text` properties.
3395
- """
3396
- if fontdict is not None :
3397
- kwargs .update (fontdict )
3398
- ret = self .xaxis .set_ticklabels (labels ,
3399
- minor = minor , ** kwargs )
3400
- self .stale = True
3401
- return ret
3365
+ set_xticklabels = _axis_method_wrapper (
3366
+ "xaxis" , "_set_ticklabels" ,
3367
+ doc_sub = {"Axis.set_ticks" : "Axes.set_xticks" })
3402
3368
3403
3369
def invert_yaxis (self ):
3404
3370
"""
@@ -3665,47 +3631,9 @@ def set_yscale(self, value, **kwargs):
3665
3631
get_ymajorticklabels = _axis_method_wrapper ("yaxis" , "get_majorticklabels" )
3666
3632
get_yminorticklabels = _axis_method_wrapper ("yaxis" , "get_minorticklabels" )
3667
3633
get_yticklabels = _axis_method_wrapper ("yaxis" , "get_ticklabels" )
3668
-
3669
- @cbook ._make_keyword_only ("3.3" , "fontdict" )
3670
- def set_yticklabels (self , labels , fontdict = None , minor = False , ** kwargs ):
3671
- """
3672
- Set the y-tick labels with list of string labels.
3673
-
3674
- .. warning::
3675
- This method should only be used after fixing the tick positions
3676
- using `~.axes.Axes.set_yticks`. Otherwise, the labels may end up
3677
- in unexpected positions.
3678
-
3679
- Parameters
3680
- ----------
3681
- labels : list of str
3682
- The label texts.
3683
-
3684
- fontdict : dict, optional
3685
- A dictionary controlling the appearance of the ticklabels.
3686
- The default *fontdict* is::
3687
-
3688
- {'fontsize': rcParams['axes.titlesize'],
3689
- 'fontweight': rcParams['axes.titleweight'],
3690
- 'verticalalignment': 'baseline',
3691
- 'horizontalalignment': loc}
3692
-
3693
- minor : bool, default: False
3694
- Whether to set the minor ticklabels rather than the major ones.
3695
-
3696
- Returns
3697
- -------
3698
- labels
3699
- A list of `~.text.Text` instances.
3700
-
3701
- Other Parameters
3702
- ----------------
3703
- **kwargs : `~.text.Text` properties.
3704
- """
3705
- if fontdict is not None :
3706
- kwargs .update (fontdict )
3707
- return self .yaxis .set_ticklabels (labels ,
3708
- minor = minor , ** kwargs )
3634
+ set_yticklabels = _axis_method_wrapper (
3635
+ "yaxis" , "_set_ticklabels" ,
3636
+ doc_sub = {"Axis.set_ticks" : "Axes.set_yticks" })
3709
3637
3710
3638
def xaxis_date (self , tz = None ):
3711
3639
"""
0 commit comments