Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ac7256

Browse files
authored
Merge pull request #16674 from anntzer/legend
Docstring + import cleanups to legend.py.
2 parents dbc35a9 + 2c34ad3 commit 7ac7256

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

lib/matplotlib/legend.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
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
2121
information.
2222
"""
2323

@@ -26,7 +26,7 @@
2626

2727
import numpy as np
2828

29-
from matplotlib import rcParams
29+
import matplotlib as mpl
3030
from matplotlib import cbook, docstring
3131
from matplotlib.artist import Artist, allow_rasterization
3232
from matplotlib.cbook import silent_list
@@ -162,7 +162,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
162162
ncol : 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.
@@ -254,8 +254,8 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
254254
255255
handler_map : dict or None
256256
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`.
259259
""")
260260

261261

@@ -348,7 +348,7 @@ def __init__(self, parent, handles, labels,
348348
Users can specify any arbitrary location for the legend using the
349349
*bbox_to_anchor* keyword argument. *bbox_to_anchor* can be a
350350
`.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.
352352
353353
The legend location can be specified by setting *loc* with a tuple of
354354
2 floats, which is interpreted as the lower-left corner of the legend
@@ -364,11 +364,12 @@ def __init__(self, parent, handles, labels,
364364
if fontsize is not None:
365365
self.prop = FontProperties(size=fontsize)
366366
else:
367-
self.prop = FontProperties(size=rcParams["legend.fontsize"])
367+
self.prop = FontProperties(
368+
size=mpl.rcParams["legend.fontsize"])
368369
else:
369370
self.prop = FontProperties._from_any(prop)
370371
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"])
372373

373374
self._fontsize = self.prop.get_size_in_points()
374375

@@ -386,7 +387,7 @@ def __init__(self, parent, handles, labels,
386387
'labelspacing', 'handlelength', 'handletextpad',
387388
'borderaxespad']:
388389
if locals_view[name] is None:
389-
value = rcParams["legend." + name]
390+
value = mpl.rcParams["legend." + name]
390391
else:
391392
value = locals_view[name]
392393
setattr(self, name, value)
@@ -438,7 +439,7 @@ def __init__(self, parent, handles, labels,
438439

439440
self._loc_used_default = loc is None
440441
if loc is None:
441-
loc = rcParams["legend.loc"]
442+
loc = mpl.rcParams["legend.loc"]
442443
if not self.isaxes and loc in [0, 'best']:
443444
loc = 'upper right'
444445
if isinstance(loc, str):
@@ -473,14 +474,14 @@ def __init__(self, parent, handles, labels,
473474
# and size of the box will be updated during the drawing time.
474475

475476
if facecolor is None:
476-
facecolor = rcParams["legend.facecolor"]
477+
facecolor = mpl.rcParams["legend.facecolor"]
477478
if facecolor == 'inherit':
478-
facecolor = rcParams["axes.facecolor"]
479+
facecolor = mpl.rcParams["axes.facecolor"]
479480

480481
if edgecolor is None:
481-
edgecolor = rcParams["legend.edgecolor"]
482+
edgecolor = mpl.rcParams["legend.edgecolor"]
482483
if edgecolor == 'inherit':
483-
edgecolor = rcParams["axes.edgecolor"]
484+
edgecolor = mpl.rcParams["axes.edgecolor"]
484485

485486
self.legendPatch = FancyBboxPatch(
486487
xy=(0.0, 0.0), width=1., height=1.,
@@ -494,7 +495,7 @@ def __init__(self, parent, handles, labels,
494495
# draw()) to the length that includes the padding. Thus we set
495496
# pad=0 here.
496497
if fancybox is None:
497-
fancybox = rcParams["legend.fancybox"]
498+
fancybox = mpl.rcParams["legend.fancybox"]
498499

499500
if fancybox:
500501
self.legendPatch.set_boxstyle("round", pad=0,
@@ -506,7 +507,7 @@ def __init__(self, parent, handles, labels,
506507

507508
self._drawFrame = frameon
508509
if frameon is None:
509-
self._drawFrame = rcParams["legend.frameon"]
510+
self._drawFrame = mpl.rcParams["legend.frameon"]
510511

511512
# init with null renderer
512513
self._init_legend_box(handles, labels, markerfirst)
@@ -517,7 +518,7 @@ def __init__(self, parent, handles, labels,
517518
if shadow:
518519
self.get_frame().set_alpha(1)
519520
else:
520-
self.get_frame().set_alpha(rcParams["legend.framealpha"])
521+
self.get_frame().set_alpha(mpl.rcParams["legend.framealpha"])
521522
else:
522523
self.get_frame().set_alpha(framealpha)
523524

@@ -527,7 +528,7 @@ def __init__(self, parent, handles, labels,
527528

528529
# figure out title fontsize:
529530
if title_fontsize is None:
530-
title_fontsize = rcParams['legend.title_fontsize']
531+
title_fontsize = mpl.rcParams['legend.title_fontsize']
531532
tprop = FontProperties(size=title_fontsize)
532533
self.set_title(title, prop=tprop)
533534
self._draggable = None

0 commit comments

Comments
 (0)