@@ -158,8 +158,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
158
158
same height, set to ``[0.5]``.
159
159
160
160
ma
10000
rkerscale : float, default: :rc:`legend.markerscale`
161
- The relative size of legend markers compared with the originally
162
- drawn ones.
161
+ The relative size of legend markers compared to the originally drawn ones.
163
162
164
163
markerfirst : bool, default: True
165
164
If *True*, legend marker is placed to the left of the legend label.
@@ -254,52 +253,55 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
254
253
"""
255
254
256
255
_loc_doc_base = """
257
- loc : str or pair of floats, {0 }
256
+ loc : str or pair of floats, default: {default }
258
257
The location of the legend.
259
258
260
- The strings
261
- ``'upper left', 'upper right', 'lower left', 'lower right'``
262
- place the legend at the corresponding corner of the axes/figure .
259
+ The strings ``'upper left'``, ``'upper right'``, ``'lower left'``,
260
+ ``'lower right'`` place the legend at the corresponding corner of the
261
+ {parent} .
263
262
264
- The strings
265
- ``'upper center', 'lower center', 'center left', 'center right'``
266
- place the legend at the center of the corresponding edge of the
267
- axes/figure.
268
-
269
- The string ``'center'`` places the legend at the center of the axes/figure.
270
-
271
- The string ``'best'`` places the legend at the location, among the nine
272
- locations defined so far, with the minimum overlap with other drawn
273
- artists. This option can be quite slow for plots with large amounts of
274
- data; your plotting speed may benefit from providing a specific location.
263
+ The strings ``'upper center'``, ``'lower center'``, ``'center left'``,
264
+ ``'center right'`` place the legend at the center of the corresponding edge
265
+ of the {parent}.
275
266
267
+ The string ``'center'`` places the legend at the center of the {parent}.
268
+ {best}
276
269
The location can also be a 2-tuple giving the coordinates of the lower-left
277
- corner of the legend in axes coordinates (in which case *bbox_to_anchor*
270
+ corner of the legend in {parent} coordinates (in which case *bbox_to_anchor*
278
271
will be ignored).
279
272
280
273
For back-compatibility, ``'center right'`` (but no other location) can also
281
- be spelled ``'right'``, and each "string" locations can also be given as a
274
+ be spelled ``'right'``, and each "string" location can also be given as a
282
275
numeric value:
283
276
284
- =============== =============
285
- Location String Location Code
286
- =============== =============
287
- 'best' 0
288
- 'upper right' 1
289
- 'upper left' 2
290
- 'lower left' 3
291
- 'lower right' 4
292
- 'right' 5
293
- 'center left' 6
294
- 'center right' 7
295
- 'lower center' 8
296
- 'upper center' 9
297
- 'center' 10
298
- =============== =============
299
- {1}"""
300
-
301
- _legend_kw_axes_st = (_loc_doc_base .format ("default: :rc:`legend.loc`" , '' ) +
302
- _legend_kw_doc_base )
277
+ ================== =============
278
+ Location String Location Code
279
+ ================== =============
280
+ 'best' (Axes only) 0
281
+ 'upper right' 1
282
+ 'upper left' 2
283
+ 'lower left' 3
284
+ 'lower right' 4
285
+ 'right' 5
286
+ 'center left' 6
287
+ 'center right' 7
288
+ 'lower center' 8
289
+ 'upper center' 9
290
+ 'center' 10
291
+ ================== =============
292
+ {outside}"""
293
+
294
+ _loc_doc_best = """
295
+ The string ``'best'`` places the legend at the location, among the nine
296
+ locations defined so far, with the minimum overlap with other drawn
297
+ artists. This option can be quite slow for plots with large amounts of
298
+ data; your plotting speed may benefit from providing a specific location.
299
+ """
300
+
301
+ _legend_kw_axes_st = (
302
+ _loc_doc_base .format (parent = 'axes' , default = ':rc:`legend.loc`' ,
303
+ best = _loc_doc_best , outside = '' ) +
304
+ _legend_kw_doc_base )
303
305
_docstring .interpd .update (_legend_kw_axes = _legend_kw_axes_st )
304
306
305
307
_outside_doc = """
@@ -314,21 +316,23 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
314
316
:doc:`/tutorials/intermediate/legend_guide` for more details.
315
317
"""
316
318
317
- _legend_kw_figure_st = (_loc_doc_base .format ("default: 'upper right'" ,
318
- _outside_doc ) +
319
- _legend_kw_doc_base )
319
+ _legend_kw_figure_st = (
320
+ _loc_doc_base .format (parent = 'figure' , default = "'upper right'" ,
321
+ best = '' , outside = _outside_doc ) +
322
+ _legend_kw_doc_base )
320
323
_docstring .interpd .update (_legend_kw_figure = _legend_kw_figure_st )
321
324
322
325
_legend_kw_both_st = (
323
- _loc_doc_base .format ("default: 'best' for axes, 'upper right' for figures" ,
324
- _outside_doc ) +
326
+ _loc_doc_base .format (parent = 'axes/figure' ,
327
+ default = ":rc:`legend.loc` for Axes, 'upper right' for Figure" ,
328
+ best = _loc_doc_best , outside = _outside_doc ) +
325
329
_legend_kw_doc_base )
326
330
_docstring .interpd .update (_legend_kw_doc = _legend_kw_both_st )
327
331
328
332
329
333
class Legend (Artist ):
330
334
"""
331
- Place a legend on the axes at location loc .
335
+ Place a legend on the figure/ axes.
332
336
"""
333
337
334
338
# 'best' is only implemented for axes legends
@@ -407,17 +411,6 @@ def __init__(
407
411
List of `.Artist` objects added as legend entries.
408
412
409
413
.. versionadded:: 3.7
410
-
411
- Notes
412
- -----
413
- Users can specify any arbitrary location for the legend using the
414
- *bbox_to_anchor* keyword argument. *bbox_to_anchor* can be a
6957
415
- `.BboxBase` (or derived there from) or a tuple of 2 or 4 floats.
416
- See `set_bbox_to_anchor` for more detail.
417
-
418
- The legend location can be specified by setting *loc* with a tuple of
419
- 2 floats, which is interpreted as the lower-left corner of the legend
420
- in the normalized axes coordinate.
421
414
"""
422
415
# local import only to avoid circularity
423
416
from matplotlib .axes import Axes
0 commit comments