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,7 +132,23 @@ 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 ):
139
+ """
140
+ Parameters
141
+ ----------
142
+ marker_pad : float
143
+ Padding between points in legend entry.
144
+
145
+ numpoints : int
146
+ Number of points to show in legend entry.
147
+
148
+ Notes
149
+ -----
150
+ Any other keyword arguments are given to `HandlerBase`.
151
+ """
137
152
HandlerBase .__init__ (self , ** kw )
138
153
139
154
self ._numpoints = numpoints
@@ -162,7 +177,25 @@ def get_xdata(self, legend, xdescent, ydescent, width, height, fontsize):
162
177
163
178
164
179
class HandlerNpointsYoffsets (HandlerNpoints ):
180
+ """
181
+ A legend handler that shows *numpoints* in the legend, and allows them to
182
+ be individually offest in the y-direction.
183
+ """
165
184
def __init__ (self , numpoints = None , yoffsets = None , ** kw ):
185
+ """
186
+ Parameters
187
+ ----------
188
+ numpoints : int
189
+ Number of points to show in legend entry.
190
+
191
+ yoffsets : array of floats
192
+ Length *numpoints* list of y offsets for each point in
193
+ legend entry.
194
+
195
+ Notes
196
+ -----
197
+ Any other keyword arguments are given to `HandlerNpoints`.
198
+ """
166
199
HandlerNpoints .__init__ (self , numpoints = numpoints , ** kw )
167
200
self ._yoffsets = yoffsets
168
201
@@ -177,10 +210,24 @@ def get_ydata(self, legend, xdescent, ydescent, width, height, fontsize):
177
210
178
211
class HandlerLine2D (HandlerNpoints ):
179
212
"""
180
- Handler for Line2D instances.
213
+ Handler for `. Line2D` instances.
181
214
"""
182
215
def __init__ (self , marker_pad = 0.3 , numpoints = None , ** kw ):
183
- HandlerNpoints .__init__ (self , marker_pad = marker_pad , numpoints = numpoints , ** kw )
216
+ """
217
+ Parameters
218
+ ----------
219
+ marker_pad : float
220
+ Padding between points in legend entry.
221
+
222
+ numpoints : int
223
+ Number of points to show in legend entry.
224
+
225
+ Notes
226
+ -----
227
+ Any other keyword arguments are given to `HandlerNpoints`.
228
+ """
229
+ HandlerNpoints .__init__ (self , marker_pad = marker_pad ,
230
+ numpoints = numpoints , ** kw )
184
231
185
232
def create_artists (self , legend , orig_handle ,
186
233
xdescent , ydescent , width , height , fontsize ,
@@ -215,21 +262,26 @@ def create_artists(self, legend, orig_handle,
215
262
216
263
class HandlerPatch (HandlerBase ):
217
264
"""
218
- Handler for Patch instances.
265
+ Handler for `. Patch` instances.
219
266
"""
220
267
def __init__ (self , patch_func = None , ** kw ):
221
268
"""
222
- The HandlerPatch class optionally takes a function ``patch_func``
223
- who's responsibility is to create the legend key artist. The
224
- ``patch_func`` should have the signature::
269
+ Parameters
270
+ ----------
271
+ patch_func : callable, optional
272
+ The function that creates the legend key artist.
273
+ *patch_func* should have the signature::
225
274
226
- def patch_func(legend=legend, orig_handle=orig_handle,
227
- xdescent=xdescent, ydescent=ydescent,
228
- width=width, height=height, fontsize=fontsize)
275
+ def patch_func(legend=legend, orig_handle=orig_handle,
276
+ xdescent=xdescent, ydescent=ydescent,
277
+ width=width, height=height, fontsize=fontsize)
229
278
230
- Subsequently the created artist will have its ``update_prop`` method
231
- called and the appropriate transform will be applied.
279
+ Subsequently the created artist will have its ``update_prop`` method
280
+ called and the appropriate transform will be applied.
232
281
282
+ Notes
283
+ -----
284
+ Any other keyword arguments are given to `HandlerBase`.
233
285
"""
234
286
HandlerBase .__init__ (self , ** kw )
235
287
self ._patch_func = patch_func
@@ -256,7 +308,7 @@ def create_artists(self, legend, orig_handle,
256
308
257
309
class HandlerLineCollection (HandlerLine2D ):
258
310
"""
259
- Handler for LineCollection instances.
311
+ Handler for `. LineCollection` instances.
260
312
"""
261
313
def get_numpoints (self , legend ):
262
314
if self ._numpoints is None :
@@ -288,7 +340,7 @@ def create_artists(self, legend, orig_handle,
288
340
289
341
class HandlerRegularPolyCollection (HandlerNpointsYoffsets ):
290
342
"""
291
- Handler for RegularPolyCollections.
343
+ Handler for `. RegularPolyCollections` .
292
344
"""
293
345
def __init__ (self , yoffsets = None , sizes = None , ** kw ):
294
346
HandlerNpointsYoffsets .__init__ (self , yoffsets = yoffsets , ** kw )
@@ -302,7 +354,7 @@ def get_numpoints(self, legend):
302
354
return self ._numpoints
303
355
304
356
def get_sizes (self , legend , orig_handle ,
305
- xdescent , ydescent , width , height , fontsize ):
357
+ xdescent , ydescent , width , height , fontsize ):
306
358
if self ._sizes is None :
307
359
handle_sizes = orig_handle .get_sizes ()
308
360
if not len (handle_sizes ):
@@ -363,7 +415,7 @@ def create_artists(self, legend, orig_handle,
363
415
364
416
class HandlerPathCollection (HandlerRegularPolyCollection ):
365
417
"""
366
- Handler for PathCollections, which are used by scatter
418
+ Handler for `. PathCollections` , which are used by `~.Axes. scatter`.
367
419
"""
368
420
def create_collection (self , orig_handle , sizes , offsets , transOffset ):
369
421
p = type (orig_handle )([orig_handle .get_paths ()[0 ]],
@@ -376,7 +428,7 @@ def create_collection(self, orig_handle, sizes, offsets, transOffset):
376
428
377
429
class HandlerCircleCollection (HandlerRegularPolyCollection ):
378
430
"""
379
- Handler for CircleCollections
431
+ Handler for `. CircleCollections`.
380
432
"""
381
433
def create_collection (self , orig_handle , sizes , offsets , transOffset ):
382
434
p = type (orig_handle )(sizes ,
@@ -388,7 +440,7 @@ def create_collection(self, orig_handle, sizes, offsets, transOffset):
388
440
389
441
class HandlerErrorbar (HandlerLine2D ):
390
442
"""
391
- Handler for Errorbars
443
+ Handler for Errorbars.
392
444
"""
393
445
def __init__ (self , xerr_size = 0.5 , yerr_size = None ,
394
446
marker_pad = 0.3 , numpoints = None , ** kw ):
@@ -501,10 +553,29 @@ def create_artists(self, legend, orig_handle,
501
553
502
554
class HandlerStem (HandlerNpointsYoffsets ):
503
555
"""
504
- Handler for Errorbars
556
+ Handler for plots produced by `~.Axes.stem`.
505
557
"""
506
558
def __init__ (self , marker_pad = 0.3 , numpoints = None ,
507
559
bottom = None , yoffsets = None , ** kw ):
560
+ """
561
+ Parameters
562
+ ----------
563
+ marker_pad : float
564
+ Padding between points in legend entry. Default is 0.3.
565
+
566
+ numpoints : int, optional
567
+ Number of points to show in legend entry.
568
+
569
+ bottom : float, optional
570
+
571
+ yoffsets : array of floats, optional
572
+ Length *numpoints* list of y offsets for each point in
573
+ legend entry.
574
+
575
+ Notes
576
+ -----
577
+ Any other keyword arguments are given to `HandlerNpointsYoffsets`.
578
+ """
508
579
509
580
HandlerNpointsYoffsets .__init__ (self , marker_pad = marker_pad ,
510
581
numpoints = numpoints ,
@@ -571,18 +642,14 @@ class HandlerTuple(HandlerBase):
571
642
572
643
Parameters
573
644
----------
574
-
575
645
ndivide : int, optional
576
- The number of sections to divide the legend area into. If None,
646
+ The number of sections to divide the legend area into. If None,
577
647
use the length of the input tuple. Default is 1.
578
648
579
649
580
650
pad : float, optional
581
- If None, fall back to `legend.borderpad` as the default.
651
+ If None, fall back to `` legend.borderpad` ` as the default.
582
652
In units of fraction of font size. Default is None.
583
-
584
-
585
-
586
653
"""
587
654
def __init__ (self , ndivide = 1 , pad = None , ** kwargs ):
588
655
@@ -628,7 +695,7 @@ def create_artists(self, legend, orig_handle,
628
695
629
696
class HandlerPolyCollection (HandlerBase ):
630
697
"""
631
- Handler for PolyCollection used in fill_between and stackplot.
698
+ Handler for `. PolyCollection` used in `~.Axes. fill_between` and `~.Axes. stackplot` .
632
699
"""
633
700
def _update_prop (self , legend_handle , orig_handle ):
634
701
def first_color (colors ):
@@ -639,6 +706,7 @@ def first_color(colors):
639
706
return colors [0 ]
640
707
else :
641
708
return "none"
709
+
642
710
def get_first (prop_array ):
643
711
if len (prop_array ):
644
712
return prop_array [0 ]
0 commit comments