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.
@@ -253,8 +253,8 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
253
253
254
254
handler_map : dict or None
255
255
The custom dictionary mapping instances or types to a legend
256
- handler. This ` handler_map` updates the default handler map
257
- found at :func: `matplotlib.legend.Legend.get_legend_handler_map`.
256
+ handler. This * handler_map* updates the default handler map
257
+ found at `matplotlib.legend.Legend.get_legend_handler_map`.
258
258
""" )
259
259
260
260
@@ -347,7 +347,7 @@ def __init__(self, parent, handles, labels,
347
347
Users can specify any arbitrary location for the legend using the
348
348
*bbox_to_anchor* keyword argument. *bbox_to_anchor* can be a
349
349
`.BboxBase` (or derived therefrom) or a tuple of 2 or 4 floats.
350
- See :meth: `set_bbox_to_anchor` for more detail.
350
+ See `set_bbox_to_anchor` for more detail.
351
351
352
352
The legend location can be specified by setting *loc* with a tuple of
353
353
2 floats, which is interpreted as the lower-left corner of the legend
@@ -363,11 +363,12 @@ def __init__(self, parent, handles, labels,
363
363
if fontsize is not None :
364
364
self .prop = FontProperties (size = fontsize )
365
365
else :
366
- self .prop = FontProperties (size = rcParams ["legend.fontsize" ])
366
+ self .prop = FontProperties (
367
+ size = mpl .rcParams ["legend.fontsize" ])
367
368
else :
368
369
self .prop = FontProperties ._from_any (prop )
369
370
if isinstance (prop , dict ) and "size" not in prop :
370
- self .prop .set_size (rcParams ["legend.fontsize" ])
371
+ self .prop .set_size (mpl . rcParams ["legend.fontsize" ])
371
372
372
373
self ._fontsize = self .prop .get_size_in_points ()
373
374
@@ -385,7 +386,7 @@ def __init__(self, parent, handles, labels,
385
386
'labelspacing' , 'handlelength' , 'handletextpad' ,
386
387
'borderaxespad' ]:
387
388
if locals_view [name ] is None :
388
- value = rcParams ["legend." + name ]
389
+ value = mpl . rcParams ["legend." + name ]
389
390
else :
390
391
value = locals_view [name ]
391
392
setattr (self , name , value )
@@ -437,7 +438,7 @@ def __init__(self, parent, handles, labels,
437
438
438
439
self ._loc_used_default = loc is None
439
440
if loc is None :
440
- loc = rcParams ["legend.loc" ]
441
+ loc = mpl . rcParams ["legend.loc" ]
441
442
if not self .isaxes and loc in [0 , 'best' ]:
442
443
loc = 'upper right'
443
444
if isinstance (loc , str ):
@@ -472,14 +473,14 @@ def __init__(self, parent, handles, labels,
472
473
# and size of the box will be updated during the drawing time.
473
474
474
475
if facecolor is None :
475
- facecolor = rcParams ["legend.facecolor" ]
476
+ facecolor = mpl . rcParams ["legend.facecolor" ]
476
477
if facecolor == 'inherit' :
477
- facecolor = rcParams ["axes.facecolor" ]
478
+ facecolor = mpl . rcParams ["axes.facecolor" ]
478
479
479
480
if edgecolor is None :
480
- edgecolor = rcParams ["legend.edgecolor" ]
481
+ edgecolor = mpl . rcParams ["legend.edgecolor" ]
481
482
if edgecolor == 'inherit' :
482
- edgecolor = rcParams ["axes.edgecolor" ]
483
+ edgecolor = mpl . rcParams ["axes.edgecolor" ]
483
484
484
485
self .legendPatch = FancyBboxPatch (
485
486
xy = (0.0 , 0.0 ), width = 1. , height = 1. ,
@@ -493,7 +494,7 @@ def __init__(self, parent, handles, labels,
493
494
# draw()) to the length that includes the padding. Thus we set
494
495
# pad=0 here.
495
496
if fancybox is None :
496
- fancybox = rcParams ["legend.fancybox" ]
497
+ fancybox = mpl . rcParams ["legend.fancybox" ]
497
498
498
499
if fancybox :
499
500
self .legendPatch .set_boxstyle ("round" , pad = 0 ,
@@ -505,7 +506,7 @@ def __init__(self, parent, handles, labels,
505
506
506
507
self ._drawFrame = frameon
507
508
if frameon is None :
508
- self ._drawFrame = rcParams ["legend.frameon" ]
509
+ self ._drawFrame = mpl . rcParams ["legend.frameon" ]
509
510
510
511
# init with null renderer
511
512
self ._init_legend_box (handles , labels , markerfirst )
@@ -516,7 +517,7 @@ def __init__(self, parent, handles, labels,
516
517
if shadow :
517
518
self .get_frame ().set_alpha (1 )
518
519
else :
519
- self .get_frame ().set_alpha (rcParams ["legend.framealpha" ])
520
+ self .get_frame ().set_alpha (mpl . rcParams ["legend.framealpha" ])
520
521
else :
521
522
self .get_frame ().set_alpha (framealpha )
522
523
@@ -526,7 +527,7 @@ def __init__(self, parent, handles, labels,
526
527
527
528
# figure out title fontsize:
528
529
if title_fontsize is None :
529
- title_fontsize = rcParams ['legend.title_fontsize' ]
530
+ title_fontsize = mpl . rcParams ['legend.title_fontsize' ]
530
531
tprop = FontProperties (size = title_fontsize )
531
532
self .set_title (title , prop = tprop )
532
533
self ._draggable = None
0 commit comments