44
55.. important::
66
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
2121information.
2222"""
2323
2626
2727import numpy as np
2828
29- from matplotlib import rcParams
29+ import matplotlib as mpl
3030from matplotlib import cbook , docstring
3131from matplotlib .artist import Artist , allow_rasterization
3232from matplotlib .cbook import silent_list
@@ -162,7 +162,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
162162ncol : int, default: 1
163163 The number of columns that the legend has.
164164
165- prop : None or :class: `matplotlib.font_manager.FontProperties` or dict
165+ prop : None or `matplotlib.font_manager.FontProperties` or dict
166166 The font properties of the legend. If None (default), the current
167167 :data:`matplotlib.rcParams` will be used.
168168
@@ -222,7 +222,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
222222 expanded to fill the axes area (or *bbox_to_anchor* if defines
223223 the legend's size).
224224
225- bbox_transform : None or :class: `matplotlib.transforms.Transform`
225+ bbox_transform : None or `matplotlib.transforms.Transform`
226226 The transform for the bounding box (*bbox_to_anchor*). For a value
227227 of ``None`` (default) the Axes'
228228 :data:`~matplotlib.axes.Axes.transAxes` transform will be used.
@@ -253,8 +253,8 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
253253
254254handler_map : dict or None
255255 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`.
258258""" )
259259
260260
@@ -347,7 +347,7 @@ def __init__(self, parent, handles, labels,
347347 Users can specify any arbitrary location for the legend using the
348348 *bbox_to_anchor* keyword argument. *bbox_to_anchor* can be a
349349 `.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.
351351
352352 The legend location can be specified by setting *loc* with a tuple of
353353 2 floats, which is interpreted as the lower-left corner of the legend
@@ -363,11 +363,12 @@ def __init__(self, parent, handles, labels,
363363 if fontsize is not None :
364364 self .prop = FontProperties (size = fontsize )
365365 else :
366- self .prop = FontProperties (size = rcParams ["legend.fontsize" ])
366+ self .prop = FontProperties (
367+ size = mpl .rcParams ["legend.fontsize" ])
367368 else :
368369 self .prop = FontProperties ._from_any (prop )
369370 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" ])
371372
372373 self ._fontsize = self .prop .get_size_in_points ()
373374
@@ -385,7 +386,7 @@ def __init__(self, parent, handles, labels,
385386 'labelspacing' , 'handlelength' , 'handletextpad' ,
386387 'borderaxespad' ]:
387388 if locals_view [name ] is None :
388- value = rcParams ["legend." + name ]
389+ value = mpl . rcParams ["legend." + name ]
389390 else :
390391 value = locals_view [name ]
391392 setattr (self , name , value )
@@ -437,7 +438,7 @@ def __init__(self, parent, handles, labels,
437438
438439 self ._loc_used_default = loc is None
439440 if loc is None :
440- loc = rcParams ["legend.loc" ]
441+ loc = mpl . rcParams ["legend.loc" ]
441442 if not self .isaxes and loc in [0 , 'best' ]:
442443 loc = 'upper right'
443444 if isinstance (loc , str ):
@@ -472,14 +473,14 @@ def __init__(self, parent, handles, labels,
472473 # and size of the box will be updated during the drawing time.
473474
474475 if facecolor is None :
475- facecolor = rcParams ["legend.facecolor" ]
476+ facecolor = mpl . rcParams ["legend.facecolor" ]
476477 if facecolor == 'inherit' :
477- facecolor = rcParams ["axes.facecolor" ]
478+ facecolor = mpl . rcParams ["axes.facecolor" ]
478479
479480 if edgecolor is None :
480- edgecolor = rcParams ["legend.edgecolor" ]
481+ edgecolor = mpl . rcParams ["legend.edgecolor" ]
481482 if edgecolor == 'inherit' :
482- edgecolor = rcParams ["axes.edgecolor" ]
483+ edgecolor = mpl . rcParams ["axes.edgecolor" ]
483484
484485 self .legendPatch = FancyBboxPatch (
485486 xy = (0.0 , 0.0 ), width = 1. , height = 1. ,
@@ -493,7 +494,7 @@ def __init__(self, parent, handles, labels,
493494 # draw()) to the length that includes the padding. Thus we set
494495 # pad=0 here.
495496 if fancybox is None :
496- fancybox = rcParams ["legend.fancybox" ]
497+ fancybox = mpl . rcParams ["legend.fancybox" ]
497498
498499 if fancybox :
499500 self .legendPatch .set_boxstyle ("round" , pad = 0 ,
@@ -505,7 +506,7 @@ def __init__(self, parent, handles, labels,
505506
506507 self ._drawFrame = frameon
507508 if frameon is None :
508- self ._drawFrame = rcParams ["legend.frameon" ]
509+ self ._drawFrame = mpl . rcParams ["legend.frameon" ]
509510
510511 # init with null renderer
511512 self ._init_legend_box (handles , labels , markerfirst )
@@ -516,7 +517,7 @@ def __init__(self, parent, handles, labels,
516517 if shadow :
517518 self .get_frame ().set_alpha (1 )
518519 else :
519- self .get_frame ().set_alpha (rcParams ["legend.framealpha" ])
520+ self .get_frame ().set_alpha (mpl . rcParams ["legend.framealpha" ])
520521 else :
521522 self .get_frame ().set_alpha (framealpha )
522523
@@ -526,7 +527,7 @@ def __init__(self, parent, handles, labels,
526527
527528 # figure out title fontsize:
528529 if title_fontsize is None :
529- title_fontsize = rcParams ['legend.title_fontsize' ]
530+ title_fontsize = mpl . rcParams ['legend.title_fontsize' ]
530531 tprop = FontProperties (size = title_fontsize )
531532 self .set_title (title , prop = tprop )
532533 self ._draggable = None
0 commit comments