9
9
</tutorials/intermediate/legend_guide>` before reading this documentation.
10
10
11
11
Legend handlers are expected to be a callable object with a following
12
- signature. ::
12
+ signature::
13
13
14
14
legend_handler(legend, orig_handle, fontsize, handlebox)
15
15
16
16
Where *legend* is the legend itself, *orig_handle* is the original
17
- plot, *fontsize* is the fontsize in pixels, and *handlebox* isa
18
- OffsetBox instance. Within the call, you should create relevant
17
+ plot, *fontsize* is the fontsize in pixels, and *handlebox* isan
18
+ `. OffsetBox` instance. Within the call, you should create relevant
19
19
artists (using relevant properties from the *legend* and/or
20
- *orig_handle*) and add them into the handlebox. The artists need to
21
- be scaled according to the fontsize (note that the size is inpixel ,
20
+ *orig_handle*) and add them into the* handlebox* . The artists need to
21
+ be scaled according to the* fontsize* (note that the size is inpixels ,
22
22
i.e., this is dpi-scaled value).
23
23
24
24
This module includes definition of several legend handler classes
@@ -49,7 +49,7 @@ class HandlerBase:
49
49
A base class for default legend handlers.
50
50
51
51
The derived classes are meant to override *create_artists* method, which
52
- hasa following signature. ::
52
+ hasthe following signature::
53
53
54
54
def create_artists(self, legend, orig_handle,
55
55
xdescent, ydescent, width, height, fontsize,
@@ -61,6 +61,18 @@ def create_artists(self, legend, orig_handle,
61
61
62
62
"""
63
63
def __init__ (self ,xpad = 0. ,ypad = 0. ,update_func = None ):
64
+ """
65
+ Parameters
66
+ ----------
67
+
68
+ xpad : float, optional
69
+ Padding in x-direction.
70
+ ypad : float, optional
71
+ Padding in y-direction.
72
+ update_func : callable, optional
73
+ Function for updating the legend handler properties from another
74
+ legend handler, used by `~HandlerBase.update_prop`.
75
+ """
64
76
self ._xpad ,self ._ypad = xpad ,ypad
65
77
self ._update_prop_func = update_func
66
78
@@ -133,6 +145,26 @@ def legend_artist(self, legend, orig_handle,
133
145
def create_artists (self ,legend ,orig_handle ,
134
146
xdescent ,ydescent ,width ,height ,fontsize ,
135
147
trans ):
148
+ """
149
+ Return the legend artists generated.
150
+
151
+ Parameters
152
+ ----------
153
+ legend : `~matplotlib.legend.Legend`
154
+ The legend for which these legend artists are being created.
155
+ orig_handle : `~matplotlib.artist.Artist` or similar
156
+ The object for which these legend artists are being created.
157
+ xdescent, ydescent, width, height : int
158
+ The rectangle (*xdescent*, *ydescent*, *width*, *height*) that the
159
+ legend artists being created should fit within.
160
+ fontsize : int
161
+ The fontsize in pixels. The legend artists being created should
162
+ be scaled according to the given fontsize.
163
+ trans : `~matplotlib.transforms.Transform`
164
+ The transform that is applied to the legend artists being created.
165
+ Typically from unit coordinates in the handler box to screen
166
+ coordinates.
167
+ """
136
168
raise NotImplementedError ('Derived must override' )
137
169
138
170
@@ -217,7 +249,7 @@ class HandlerLine2DCompound(HandlerNpoints):
217
249
def create_artists (self ,legend ,orig_handle ,
218
250
xdescent ,ydescent ,width ,height ,fontsize ,
219
251
trans ):
220
-
252
+ # docstring inherited
221
253
xdata ,xdata_marker = self .get_xdata (legend ,xdescent ,ydescent ,
222
254
width ,height ,fontsize )
223
255
@@ -276,7 +308,7 @@ class HandlerLine2D(HandlerNpoints):
276
308
def create_artists (self ,legend ,orig_handle ,
277
309
xdescent ,ydescent ,width ,height ,fontsize ,
278
310
trans ):
279
-
311
+ # docstring inherited
280
312
xdata ,xdata_marker = self .get_xdata (legend ,xdescent ,ydescent ,
281
313
width ,height ,fontsize )
282
314
@@ -341,6 +373,7 @@ def _create_patch(self, legend, orig_handle,
341
373
342
374
def create_artists (self ,legend ,orig_handle ,
343
375
xdescent ,ydescent ,width ,height ,fontsize ,trans ):
376
+ # docstring inherited
344
377
p = self ._create_patch (legend ,orig_handle ,
345
378
xdescent ,ydescent ,width ,height ,fontsize )
346
379
self .update_prop (p ,orig_handle ,legend )
@@ -374,6 +407,7 @@ def _create_line(orig_handle, width, height):
374
407
375
408
def create_artists (self ,legend ,orig_handle ,
376
409
xdescent ,ydescent ,width ,height ,fontsize ,trans ):
410
+ # docstring inherited
377
411
if orig_handle .get_fill ()or (orig_handle .get_hatch ()is not None ):
378
412
p = self ._create_patch (orig_handle ,xdescent ,ydescent ,width ,
379
413
height )
@@ -404,7 +438,7 @@ def _default_update_prop(self, legend_handle, orig_handle):
404
438
405
439
def create_artists (self ,legend ,orig_handle ,
406
440
xdescent ,ydescent ,width ,height ,fontsize ,trans ):
407
-
441
+ # docstring inherited
408
442
xdata ,xdata_marker = self .get_xdata (legend ,xdescent ,ydescent ,
409
443
width ,height ,fontsize )
410
444
ydata = np .full_like (xdata , (height - ydescent )/ 2 )
@@ -471,6 +505,7 @@ def create_collection(self, orig_handle, sizes, offsets, offset_transform):
471
505
def create_artists (self ,legend ,orig_handle ,
472
506
xdescent ,ydescent ,width ,height ,fontsize ,
473
507
trans ):
508
+ # docstring inherited
474
509
xdata ,xdata_marker = self .get_xdata (legend ,xdescent ,ydescent ,
475
510
width ,height ,fontsize )
476
511
@@ -534,7 +569,7 @@ def get_err_size(self, legend, xdescent, ydescent,
534
569
def create_artists (self ,legend ,orig_handle ,
535
570
xdescent ,ydescent ,width ,height ,fontsize ,
536
571
trans ):
537
-
572
+ # docstring inherited
538
573
plotlines ,caplines ,barlinecols = orig_handle
539
574
540
575
xdata ,xdata_marker = self .get_xdata (legend ,xdescent ,ydescent ,
@@ -653,6 +688,7 @@ def get_ydata(self, legend, xdescent, ydescent, width, height, fontsize):
653
688
def create_artists (self ,legend ,orig_handle ,
654
689
xdescent ,ydescent ,width ,height ,fontsize ,
655
690
trans ):
691
+ # docstring inherited
656
692
markerline ,stemlines ,baseline = orig_handle
657
693
# Check to see if the stemcontainer is storing lines as a list or a
658
694
# LineCollection. Eventually using a list will be removed, and this
@@ -730,7 +766,7 @@ def __init__(self, ndivide=1, pad=None, **kwargs):
730
766
def create_artists (self ,legend ,orig_handle ,
731
767
xdescent ,ydescent ,width ,height ,fontsize ,
732
768
trans ):
733
-
769
+ # docstring inherited
734
770
handler_map = legend .get_legend_handler_map ()
735
771
736
772
if self ._ndivide is None :
@@ -797,6 +833,7 @@ def get_first(prop_array):
797
833
798
834
def create_artists (self ,legend ,orig_handle ,
799
835
xdescent ,ydescent ,width ,height ,fontsize ,trans ):
836
+ # docstring inherited
800
837
p = Rectangle (xy = (- xdescent ,- ydescent ),
801
838
width = width ,height = height )
802
839
self .update_prop (p ,orig_handle ,legend )