Skip to content

Commit c5926ad

Browse files
committed
DOC: fix docstrings
1 parent c1fe98d commit c5926ad

File tree

3 files changed

+77
-58
lines changed

3 files changed

+77
-58
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def legend(self, *args, **kwargs):
283283
284284
Other Parameters
285285
----------------
286-
%(_legend_kw_doc)s
286+
%(_legend_kw_axes)s
287287
288288
See Also
289289
--------

lib/matplotlib/figure.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,17 +1085,8 @@ def legend(self, *args, **kwargs):
10851085
10861086
Other Parameters
10871087
----------------
1088-
%(_legend_kw_doc)s
1089-
1090-
If a figure is using the constrained layout manager, the string codes
1091-
of the *loc* keyword argument can get better layout behaviour using the
1092-
prefix 'outside'. There is ambiguity at the corners, so 'outside
1093-
upper right' will make space for the legend above the rest of the
1094-
axes in the layout, and 'outside right upper' will make space on the
1095-
right side of the layout. In addition to the values of *loc*
1096-
listed above, we have 'outside right upper', 'outside right lower',
1097-
'outside left upper', and 'outside left lower'. See
1098-
:doc:`/tutorials/intermediate/legend_guide` for more details.
1088+
%(_legend_kw_figure)s
1089+
10991090
11001091
See Also
11011092
--------

lib/matplotlib/legend.py

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,51 +94,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
9494
self.legend.set_bbox_to_anchor(loc_in_bbox)
9595

9696

97-
_docstring.interpd.update(_legend_kw_doc="""
98-
loc : str or pair of floats, default: :rc:`legend.loc` ('best' for axes, \
99-
'upper right' for figures)
100-
The location of the legend.
101-
102-
The strings
103-
``'upper left', 'upper right', 'lower left', 'lower right'``
104-
place the legend at the corresponding corner of the axes/figure.
105-
106-
The strings
107-
``'upper center', 'lower center', 'center left', 'center right'``
108-
place the legend at the center of the corresponding edge of the
109-
axes/figure.
110-
111-
The string ``'center'`` places the legend at the center of the axes/figure.
112-
113-
The string ``'best'`` places the legend at the location, among the nine
114-
locations defined so far, with the minimum overlap with other drawn
115-
artists. This option can be quite slow for plots with large amounts of
116-
data; your plotting speed may benefit from providing a specific location.
117-
118-
The location can also be a 2-tuple giving the coordinates of the lower-left
119-
corner of the legend in axes coordinates (in which case *bbox_to_anchor*
120-
will be ignored).
121-
122-
For back-compatibility, ``'center right'`` (but no other location) can also
123-
be spelled ``'right'``, and each "string" locations can also be given as a
124-
numeric value:
125-
126-
=============== =============
127-
Location String Location Code
128-
=============== =============
129-
'best' 0
130-
'upper right' 1
131-
'upper left' 2
132-
'lower left' 3
133-
'lower right' 4
134-
'right' 5
135-
'center left' 6
136-
'center right' 7
137-
'lower center' 8
138-
'upper center' 9
139-
'center' 10
140-
=============== =============
141-
97+
_legend_kw_doc_base = """
14298
bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
14399
Box that is used to position the legend in conjunction with *loc*.
144100
Defaults to `axes.bbox` (if called as a method to `.Axes.legend`) or
@@ -289,7 +245,79 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
289245
290246
draggable : bool, default: False
291247
Whether the legend can be dragged with the mouse.
292-
""")
248+
"""
249+
250+
_loc_doc_base = """
251+
loc : str or pair of floats, {0}
252+
The location of the legend.
253+
254+
The strings
255+
``'upper left', 'upper right', 'lower left', 'lower right'``
256+
place the legend at the corresponding corner of the axes/figure.
257+
258+
The strings
259+
``'upper center', 'lower center', 'center left', 'center right'``
260+
place the legend at the center of the corresponding edge of the
261+
axes/figure.
262+
263+
The string ``'center'`` places the legend at the center of the axes/figure.
264+
265+
The string ``'best'`` places the legend at the location, among the nine
266+
locations defined so far, with the minimum overlap with other drawn
267+
artists. This option can be quite slow for plots with large amounts of
268+
data; your plotting speed may benefit from providing a specific location.
269+
270+
The location can also be a 2-tuple giving the coordinates of the lower-left
271+
corner of the legend in axes coordinates (in which case *bbox_to_anchor*
272+
will be ignored).
273+
274+
For back-compatibility, ``'center right'`` (but no other location) can also
275+
be spelled ``'right'``, and each "string" locations can also be given as a
276+
numeric value:
277+
278+
=============== =============
279+
Location String Location Code
280+
=============== =============
281+
'best' 0
282+
'upper right' 1
283+
'upper left' 2
284+
'lower left' 3
285+
'lower right' 4
286+
'right' 5
287+
'center left' 6
288+
'center right' 7
289+
'lower center' 8
290+
'upper center' 9
291+
'center' 10
292+
=============== =============
293+
{1}"""
294+
295+
_legend_kw_axes_st = (_loc_doc_base.format("default: :rc:`legend.loc`", '') +
296+
_legend_kw_doc_base)
297+
_docstring.interpd.update(_legend_kw_axes=_legend_kw_axes_st)
298+
299+
_outside_doc = """
300+
If a figure is using the constrained layout manager, the string codes
301+
of the *loc* keyword argument can get better layout behaviour using the
302+
prefix 'outside'. There is ambiguity at the corners, so 'outside
303+
upper right' will make space for the legend above the rest of the
304+
axes in the layout, and 'outside right upper' will make space on the
305+
right side of the layout. In addition to the values of *loc*
306+
listed above, we have 'outside right upper', 'outside right lower',
307+
'outside left upper', and 'outside left lower'. See
308+
:doc:`/tutorials/intermediate/legend_guide` for more details.
309+
"""
310+
311+
_legend_kw_figure_st = (_loc_doc_base.format("default: 'upper right'",
312+
_outside_doc) +
313+
_legend_kw_doc_base)
314+
_docstring.interpd.update(_legend_kw_figure=_legend_kw_figure_st)
315+
316+
_legend_kw_both_st = (
317+
_loc_doc_base.format("default: 'best' for axes, 'upper right' for figures",
318+
_outside_doc) +
319+
_legend_kw_doc_base)
320+
_docstring.interpd.update(_legend_kw_doc=_legend_kw_both_st)
293321

294322

295323
class Legend(Artist):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy