4
4
5
5
.. important::
6
6
7
- It is unlikely that you would ever create a Legend instance
8
- manually. Most users would normally create a legend via the
9
- :meth:`~matplotlib.axes.Axes.legend` function. For more details on legends
10
- there is also a :doc:`legend guide </tutorials/intermediate/legend_guide>`.
11
-
12
- The Legend class can be considered as a container of legend handles and
13
- legend texts. Creation of corresponding legend handles from the plot elements
14
- in the axes or figures (e.g., lines, patches, etc.) are specified by the
15
- handler map, which defines the mapping between the plot elements and the
16
- legend handlers to be used ( the default legend handlers are defined in the
17
- :mod:`~matplotlib.legend_handler` module). Note that not all kinds of
18
- artist are supported by the legend yet by default but it is possible to
19
- extend the legend handler's capabilities to support arbitrary objects. See
20
- the :doc:`legend guide </tutorials/intermediate/legend_guide>` for more
7
+ It is unlikely that you would ever create a Legend instance manually.
8
+ Most users would normally create a legend via the `~.Axes.legend`
9
+ function. For more details on legends there is also a :doc:`legend guide
10
+ </tutorials/intermediate/legend_guide>`.
11
+
12
+ The ` Legend` class is a container of legend handles and legend texts.
13
+
14
+ The legend handler map specifies how to create legend handles from artists
15
+ (lines, patches, etc.) in the axes or figures. Default legend handlers are
16
+ defined in the :mod:`~matplotlib.legend_handler` module. While not all artist
17
+ types are covered by the default legend handlers, custom legend handlers can be
18
+ defined to support arbitrary objects.
19
+
20
+ See the :doc:`legend guide </tutorials/intermediate/legend_guide>` for more
21
21
information.
22
22
"""
23
23
26
26
27
27
import numpy as np
28
28
29
- from matplotlib import rcParams
29
+ import matplotlib as mpl
30
30
from matplotlib import cbook , docstring
31
31
from matplotlib .artist import Artist , allow_rasterization
32
32
from matplotlib .cbook import silent_list
@@ -162,7 +162,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
162
162
ncol : int, default: 1
163
163
The number of columns that the legend has.
164
164
165
- prop : None or :class: `matplotlib.font_manager.FontProperties` or dict
165
+ prop : None or `matplotlib.font_manager.FontProperties` or dict
166
166
The font properties of the legend. If None (default), the current
167
167
:data:`matplotlib.rcParams` will be used.
168
168
@@ -222,7 +222,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
222
222
expanded to fill the axes area (or *bbox_to_anchor* if defines
223
223
the legend's size).
224
224
225
- bbox_transform : None or :class: `matplotlib.transforms.Transform`
225
+ bbox_transform : None or `matplotlib.transforms.Transform`
226
226
The transform for the bounding box (*bbox_to_anchor*). For a value
227
227
of ``None`` (default) the Axes'
228
228
:data:`~matplotlib.axes.Axes.transAxes` transform will be used.
@@ -254,8 +254,8 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
254
254
255
255
handler_map : dict or None
256
256
The custom dictionary mapping instances or types to a legend
257
- handler. This ` handler_map` updates the default handler map
258
- found at :func: `matplotlib.legend.Legend.get_legend_handler_map`.
257
+ handler. This * handler_map* updates the default handler map
258
+ found at `matplotlib.legend.Legend.get_legend_handler_map`.
259
259
""" )
260
260
261
261
@@ -348,7 +348,7 @@ def __init__(self, parent, handles, labels,
348
348
Users can specify any arbitrary location for the legend using the
349
349
*bbox_to_anchor* keyword argument. *bbox_to_anchor* can be a
350
350
`.BboxBase` (or derived therefrom) or a tuple of 2 or 4 floats.
351
- See :meth: `set_bbox_to_anchor` for more detail.
351
+ See `set_bbox_to_anchor` for more detail.
352
352
353
353
The legend location can be specified by setting *loc* with a tuple of
354
354
2 floats, which is interpreted as the lower-left corner of the legend
@@ -364,11 +364,12 @@ def __init__(self, parent, handles, labels,
364
364
if fontsize is not None :
365
365
self .prop = FontProperties (size = fontsize )
366
366
else :
367
- self .prop = FontProperties (size = rcParams ["legend.fontsize" ])
367
+ self .prop = FontProperties (
368
+ size = mpl .rcParams ["legend.fontsize" ])
368
369
else :
369
370
self .prop = FontProperties ._from_any (prop )
370
371
if isinstance (prop , dict ) and "size" not in prop :
371
- self .prop .set_size (rcParams ["legend.fontsize" ])
372
+ self .prop .set_size (mpl . rcParams ["legend.fontsize" ])
372
373
373
374
self ._fontsize = self .prop .get_size_in_points ()
374
375
@@ -386,7 +387,7 @@ def __init__(self, parent, handles, labels,
386
387
'labelspacing' , 'handlelength' , 'handletextpad' ,
387
388
'borderaxespad' ]:
388
389
if locals_view [name ] is None :
389
- value = rcParams ["legend." + name ]
390
+ value = mpl . rcParams ["legend." + name ]
390
391
else :
391
392
value = locals_view [name ]
392
393
setattr (self , name , value )
@@ -438,7 +439,7 @@ def __init__(self, parent, handles, labels,
438
439
439
440
self ._loc_used_default = loc is None
440
441
if loc is None :
441
- loc = rcParams ["legend.loc" ]
442
+ loc = mpl . rcParams ["legend.loc" ]
442
443
if not self .isaxes and loc in [0 , 'best' ]:
443
444
loc = 'upper right'
444
445
if isinstance (loc , str ):
@@ -473,14 +474,14 @@ def __init__(self, parent, handles, labels,
473
474
# and size of the box will be updated during the drawing time.
474
475
475
476
if facecolor is None :
476
- facecolor = rcParams ["legend.facecolor" ]
477
+ facecolor = mpl . rcParams ["legend.facecolor" ]
477
478
if facecolor == 'inherit' :
478
- facecolor = rcParams ["axes.facecolor" ]
479
+ facecolor = mpl . rcParams ["axes.facecolor" ]
479
480
480
481
if edgecolor is None :
481
- edgecolor = rcParams ["legend.edgecolor" ]
482
+ edgecolor = mpl . rcParams ["legend.edgecolor" ]
482
483
if edgecolor == 'inherit' :
483
- edgecolor = rcParams ["axes.edgecolor" ]
484
+ edgecolor = mpl . rcParams ["axes.edgecolor" ]
484
485
485
486
self .legendPatch = FancyBboxPatch (
486
487
xy = (0.0 , 0.0 ), width = 1. , height = 1. ,
@@ -494,7 +495,7 @@ def __init__(self, parent, handles, labels,
494
495
# draw()) to the length that includes the padding. Thus we set
495
496
# pad=0 here.
496
497
if fancybox is None :
497
- fancybox = rcParams ["legend.fancybox" ]
498
+ fancybox = mpl . rcParams ["legend.fancybox" ]
498
499
499
500
if fancybox :
500
501
self .legendPatch .set_boxstyle ("round" , pad = 0 ,
@@ -506,7 +507,7 @@ def __init__(self, parent, handles, labels,
506
507
507
508
self ._drawFrame = frameon
508
509
if frameon is None :
509
- self ._drawFrame = rcParams ["legend.frameon" ]
510
+ self ._drawFrame = mpl . rcParams ["legend.frameon" ]
510
511
511
512
# init with null renderer
512
513
self ._init_legend_box (handles , labels , markerfirst )
@@ -517,7 +518,7 @@ def __init__(self, parent, handles, labels,
517
518
if shadow :
518
519
self .get_frame ().set_alpha (1 )
519
520
else :
520
- self .get_frame ().set_alpha (rcParams ["legend.framealpha" ])
521
+ self .get_frame ().set_alpha (mpl . rcParams ["legend.framealpha" ])
521
522
else :
522
523
self .get_frame ().set_alpha (framealpha )
523
524
@@ -527,7 +528,7 @@ def __init__(self, parent, handles, labels,
527
528
528
529
# figure out title fontsize:
529
530
if title_fontsize is None :
530
- title_fontsize = rcParams ['legend.title_fontsize' ]
531
+ title_fontsize = mpl . rcParams ['legend.title_fontsize' ]
531
532
tprop = FontProperties (size = title_fontsize )
532
533
self .set_title (title , prop = tprop )
533
534
self ._draggable = None
0 commit comments