18
18
i.e., this is dpi-scaled value).
19
19
20
20
This module includes definition of several legend handler classes
21
- derived from the base class (HandlerBase) with the following method.
21
+ derived from the base class (HandlerBase) with the following method::
22
22
23
23
def legend_artist(self, legend, orig_handle, fontsize, handlebox):
24
24
25
-
26
25
"""
27
26
from __future__ import (absolute_import , division , print_function ,
28
27
unicode_literals )
@@ -133,19 +132,22 @@ def create_artists(self, legend, orig_handle,
133
132
134
133
135
134
class HandlerNpoints (HandlerBase ):
135
+ """
136
+ A legend handler that shows *numpoints* points in the legend entry.
137
+ """
136
138
def __init__ (self , marker_pad = 0.3 , numpoints = None , ** kw ):
137
139
"""
138
140
Parameters
139
141
----------
140
142
marker_pad : float
141
- Padding between points in legend entry
143
+ Padding between points in legend entry.
142
144
143
145
numpoints : int
144
- Number of points to show in legend entry
146
+ Number of points to show in legend entry.
145
147
146
148
Notes
147
149
-----
148
- Any other keyword arguments are given to `HandlerBase`
150
+ Any other keyword arguments are given to `HandlerBase`.
149
151
"""
150
152
HandlerBase .__init__ (self , ** kw )
151
153
@@ -174,19 +176,24 @@ def get_xdata(self, legend, xdescent, ydescent, width, height, fontsize):
174
176
175
177
176
178
class HandlerNpointsYoffsets (HandlerNpoints ):
179
+ """
180
+ A legend handler that shows *numpoints* in the legend, and allows them to
181
+ be individually offest in the y-direction.
182
+ """
177
183
def __init__ (self , numpoints = None , yoffsets = None , ** kw ):
178
184
"""
179
185
Parameters
180
186
----------
181
187
numpoints : int
182
- Number of points to show in legend entry
188
+ Number of points to show in legend entry.
183
189
184
190
yoffsets : array of floats
185
- Length *numpoints* list of y offsets for each point in legend entry
191
+ Length *numpoints* list of y offsets for each point in
192
+ legend entry.
186
193
187
194
Notes
188
195
-----
189
- Any other keyword arguments are given to `HandlerNpoints`
196
+ Any other keyword arguments are given to `HandlerNpoints`.
190
197
"""
191
198
HandlerNpoints .__init__ (self , numpoints = numpoints , ** kw )
192
199
self ._yoffsets = yoffsets
@@ -202,21 +209,21 @@ def get_ydata(self, legend, xdescent, ydescent, width, height, fontsize):
202
209
203
210
class HandlerLine2D (HandlerNpoints ):
204
211
"""
205
- Handler for Line2D instances.
212
+ Handler for `. Line2D` instances.
206
213
"""
207
214
def __init__ (self , marker_pad = 0.3 , numpoints = None , ** kw ):
208
215
"""
209
216
Parameters
210
217
----------
211
218
marker_pad : float
212
- Padding between points in legend entry
219
+ Padding between points in legend entry.
213
220
214
221
numpoints : int
215
- Number of points to show in legend entry
222
+ Number of points to show in legend entry.
216
223
217
224
Notes
218
225
-----
219
- Any other keyword arguments are given to `HandlerNpoints`
226
+ Any other keyword arguments are given to `HandlerNpoints`.
220
227
"""
221
228
HandlerNpoints .__init__ (self , marker_pad = marker_pad ,
222
229
numpoints = numpoints , ** kw )
@@ -254,21 +261,26 @@ def create_artists(self, legend, orig_handle,
254
261
255
262
class HandlerPatch (HandlerBase ):
256
263
"""
257
- Handler for Patch instances.
264
+ Handler for `. Patch` instances.
258
265
"""
259
266
def __init__ (self , patch_func = None , ** kw ):
260
267
"""
261
- The HandlerPatch class optionally takes a function ``patch_func``
262
- who's responsibility is to create the legend key artist. The
263
- ``patch_func`` should have the signature::
268
+ Parameters
269
+ ----------
270
+ patch_func : callable, optional
271
+ The function that creates the legend key artist.
272
+ *patch_func* should have the signature::
264
273
265
- def patch_func(legend=legend, orig_handle=orig_handle,
266
- xdescent=xdescent, ydescent=ydescent,
267
- width=width, height=height, fontsize=fontsize)
274
+ def patch_func(legend=legend, orig_handle=orig_handle,
275
+ xdescent=xdescent, ydescent=ydescent,
276
+ width=width, height=height, fontsize=fontsize)
268
277
269
- Subsequently the created artist will have its ``update_prop`` method
270
- called and the appropriate transform will be applied.
278
+ Subsequently the created artist will have its ``update_prop`` method
279
+ called and the appropriate transform will be applied.
271
280
281
+ Notes
282
+ -----
283
+ Any other keyword arguments are given to `HandlerBase`.
272
284
"""
273
285
HandlerBase .__init__ (self , ** kw )
274
286
self ._patch_func = patch_func
@@ -295,7 +307,7 @@ def create_artists(self, legend, orig_handle,
295
307
296
308
class HandlerLineCollection (HandlerLine2D ):
297
309
"""
298
- Handler for LineCollection instances.
310
+ Handler for `. LineCollection` instances.
299
311
"""
300
312
def get_numpoints (self , legend ):
301
313
if self ._numpoints is None :
@@ -327,7 +339,7 @@ def create_artists(self, legend, orig_handle,
327
339
328
340
class HandlerRegularPolyCollection (HandlerNpointsYoffsets ):
329
341
"""
330
- Handler for RegularPolyCollections.
342
+ Handler for `. RegularPolyCollections` .
331
343
"""
332
344
def __init__ (self , yoffsets = None , sizes = None , ** kw ):
333
345
HandlerNpointsYoffsets .__init__ (self , yoffsets = yoffsets , ** kw )
@@ -341,7 +353,7 @@ def get_numpoints(self, legend):
341
353
return self ._numpoints
342
354
343
355
def get_sizes (self , legend , orig_handle ,
344
- xdescent , ydescent , width , height , fontsize ):
356
+ xdescent , ydescent , width , height , fontsize ):
345
357
if self ._sizes is None :
346
358
handle_sizes = orig_handle .get_sizes ()
347
359
if not len (handle_sizes ):
@@ -402,7 +414,7 @@ def create_artists(self, legend, orig_handle,
402
414
403
415
class HandlerPathCollection (HandlerRegularPolyCollection ):
404
416
"""
405
- Handler for PathCollections, which are used by scatter
417
+ Handler for `. PathCollections` , which are used by `~.Axes. scatter`.
406
418
"""
407
419
def create_collection (self , orig_handle , sizes , offsets , transOffset ):
408
420
p = type (orig_handle )([orig_handle .get_paths ()[0 ]],
@@ -415,7 +427,7 @@ def create_collection(self, orig_handle, sizes, offsets, transOffset):
415
427
416
428
class HandlerCircleCollection (HandlerRegularPolyCollection ):
417
429
"""
418
- Handler for CircleCollections
430
+ Handler for `. CircleCollections`.
419
431
"""
420
432
def create_collection (self , orig_handle , sizes , offsets , transOffset ):
421
433
p = type (orig_handle )(sizes ,
@@ -427,7 +439,7 @@ def create_collection(self, orig_handle, sizes, offsets, transOffset):
427
439
428
440
class HandlerErrorbar (HandlerLine2D ):
429
441
"""
430
- Handler for Errorbars
442
+ Handler for Errorbars.
431
443
"""
432
444
def __init__ (self , xerr_size = 0.5 , yerr_size = None ,
433
445
marker_pad = 0.3 , numpoints = None , ** kw ):
@@ -540,7 +552,7 @@ def create_artists(self, legend, orig_handle,
540
552
541
553
class HandlerStem (HandlerNpointsYoffsets ):
542
554
"""
543
- Handler for plots produced by `stem`
555
+ Handler for plots produced by `~.Axes. stem`.
544
556
"""
545
557
def __init__ (self , marker_pad = 0.3 , numpoints = None ,
546
558
bottom = None , yoffsets = None , ** kw ):
@@ -551,16 +563,17 @@ def __init__(self, marker_pad=0.3, numpoints=None,
551
563
Padding between points in legend entry. Default is 0.3.
552
564
553
565
numpoints : int, optional
554
- Number of points to show in legend entry
566
+ Number of points to show in legend entry.
555
567
556
568
bottom : float, optional
557
569
558
570
yoffsets : array of floats, optional
559
- Length *numpoints* list of y offsets for each point in legend entry
571
+ Length *numpoints* list of y offsets for each point in
572
+ legend entry.
560
573
561
574
Notes
562
575
-----
563
- Any other keyword arguments are given to `HandlerNpointsYoffsets`
576
+ Any other keyword arguments are given to `HandlerNpointsYoffsets`.
564
577
"""
565
578
566
579
HandlerNpointsYoffsets .__init__ (self , marker_pad = marker_pad ,
@@ -628,18 +641,14 @@ class HandlerTuple(HandlerBase):
628
641
629
642
Parameters
630
643
----------
631
-
632
644
ndivide : int, optional
633
- The number of sections to divide the legend area into. If None,
645
+ The number of sections to divide the legend area into. If None,
634
646
use the length of the input tuple. Default is 1.
635
647
636
648
637
649
pad : float, optional
638
- If None, fall back to `legend.borderpad` as the default.
650
+ If None, fall back to `` legend.borderpad` ` as the default.
639
651
In units of fraction of font size. Default is None.
640
-
641
-
642
-
643
652
"""
644
653
def __init__ (self , ndivide = 1 , pad = None , ** kwargs ):
645
654
@@ -681,7 +690,7 @@ def create_artists(self, legend, orig_handle,
681
690
682
691
class HandlerPolyCollection (HandlerBase ):
683
692
"""
684
- Handler for PolyCollection used in fill_between and stackplot.
693
+ Handler for `. PolyCollection` used in `~.Axes. fill_between` and `~.Axes. stackplot` .
685
694
"""
686
695
def _update_prop (self , legend_handle , orig_handle ):
687
696
def first_color (colors ):
@@ -692,6 +701,7 @@ def first_color(colors):
692
701
return colors [0 ]
693
702
else :
694
703
return "none"
704
+
695
705
def get_first (prop_array ):
696
706
if len (prop_array ):
697
707
return prop_array [0 ]
0 commit comments