56
56
class DraggableLegend (DraggableOffsetBox ):
57
57
def __init__ (self , legend , use_blit = False , update = "loc" ):
58
58
"""
59
- update : If "loc", update *loc* parameter of
60
- legend upon finalizing. If "bbox", update
61
- *bbox_to_anchor* parameter.
59
+ Parameters
60
+ ----------
61
+ update : string
62
+ If "loc", update *loc* parameter of legend upon finalizing.
63
+ If "bbox", update *bbox_to_anchor* parameter.
62
64
"""
63
65
self .legend = legend
64
66
@@ -581,8 +583,8 @@ def __init__(self, parent, handles, labels,
581
583
del locals_view
582
584
# trim handles and labels if illegal label...
583
585
for label , handle in zip (labels [:], handles [:]):
584
- if (isinstance (label , six .string_types )
585
- and label .startswith ('_' )):
586
+ if (isinstance (label , six .string_types ) and
587
+ label .startswith ('_' )):
586
588
warnings .warn ('The handle {!r} has a label of {!r} which '
587
589
'cannot be automatically added to the '
588
590
'legend.' .format (handle , label ))
@@ -709,7 +711,7 @@ def __init__(self, parent, handles, labels,
709
711
710
712
def _set_artist_props (self , a ):
711
713
"""
712
- set the boilerplate props for artists added to axes
714
+ Set the boilerplate props for artists added to axes.
713
715
"""
714
716
a .set_figure (self .figure )
715
717
if self .isaxes :
@@ -731,7 +733,7 @@ def _get_loc(self):
731
733
_loc = property (_get_loc , _set_loc )
732
734
733
735
def _findoffset (self , width , height , xdescent , ydescent , renderer ):
734
- "Helper function to locate the legend"
736
+ "Helper function to locate the legend. "
735
737
736
738
if self ._loc == 0 : # "best".
737
739
x , y = self ._find_best_position (width , height , renderer )
@@ -749,7 +751,7 @@ def _findoffset(self, width, height, xdescent, ydescent, renderer):
749
751
750
752
@allow_rasterization
751
753
def draw (self , renderer ):
752
- "Draw everything that belongs to the legend"
754
+ "Draw everything that belongs to the legend. "
753
755
if not self .get_visible ():
754
756
return
755
757
@@ -836,7 +838,7 @@ def update_default_handler_map(cls, handler_map):
836
838
837
839
def get_legend_handler_map (self ):
838
840
"""
839
- return the handler map.
841
+ Return the handler map.
840
842
"""
841
843
842
844
default_handler_map = self .get_default_handler_map ()
@@ -851,7 +853,7 @@ def get_legend_handler_map(self):
851
853
@staticmethod
852
854
def get_legend_handler (legend_handler_map , orig_handle ):
853
855
"""
854
- return a legend handler from *legend_handler_map* that
856
+ Return a legend handler from *legend_handler_map* that
855
857
corresponds to *orig_handler*.
856
858
857
859
*legend_handler_map* should be a dictionary object (that is
@@ -861,7 +863,7 @@ def get_legend_handler(legend_handler_map, orig_handle):
861
863
*legend_hanler_map* and return the associated value.
862
864
Otherwise, it checks for each of the classes in its
863
865
method-resolution-order. If no matching key is found, it
864
- returns None.
866
+ returns `` None`` .
865
867
"""
866
868
if is_hashable (orig_handle ):
867
869
try :
@@ -1058,11 +1060,17 @@ def _auto_legend_data(self):
1058
1060
return [vertices , bboxes , lines , offsets ]
1059
1061
1060
1062
def draw_frame (self , b ):
1061
- 'b is a boolean. Set draw frame to b'
1063
+ '''
1064
+ Set draw frame to b.
1065
+
1066
+ Parameters
1067
+ ----------
1068
+ b : bool
1069
+ '''
1062
1070
self .set_frame_on (b )
1063
1071
1064
1072
def get_children (self ):
1065
- 'return a list of child artists'
1073
+ 'Return a list of child artists. '
1066
1074
children = []
1067
1075
if self ._legend_box :
1068
1076
children .append (self ._legend_box )
@@ -1071,26 +1079,28 @@ def get_children(self):
1071
1079
return children
1072
1080
1073
1081
def get_frame (self ):
1074
- 'return the Rectangle instance used to frame the legend'
1082
+ '''
1083
+ Return the `~.patches.Rectangle` instances used to frame the legend.
1084
+ '''
1075
1085
return self .legendPatch
1076
1086
1077
1087
def get_lines (self ):
1078
- 'return a list of lines.Line2D instances in the legend'
1088
+ 'Return a list of `~. lines.Line2D` instances in the legend. '
1079
1089
return [h for h in self .legendHandles if isinstance (h , Line2D )]
1080
1090
1081
1091
def get_patches (self ):
1082
- 'return a list of patch instances in the legend'
1092
+ 'Return a list of `~.patches.Patch` instances in the legend. '
1083
1093
return silent_list ('Patch' ,
1084
1094
[h for h in self .legendHandles
1085
1095
if isinstance (h , Patch )])
1086
1096
1087
1097
def get_texts (self ):
1088
- 'return a list of text.Text instance in the legend'
1098
+ 'Return a list of `~. text.Text` instances in the legend. '
1089
1099
return silent_list ('Text' , self .texts )
1090
1100
1091
1101
def set_title (self , title , prop = None ):
1092
1102
"""
1093
- set the legend title. Fontproperties can be optionally set
1103
+ Set the legend title. Fontproperties can be optionally set
1094
1104
with *prop* parameter.
1095
1105
"""
1096
1106
self ._legend_title_box ._text .set_text (title )
@@ -1107,16 +1117,16 @@ def set_title(self, title, prop=None):
1107
1117
self .stale = True
1108
1118
1109
1119
def get_title (self ):
1110
- 'return Text instance for the legend title'
1120
+ 'Return `~.text. Text` instance for the legend title. '
1111
1121
return self ._legend_title_box ._text
1112
1122
1113
1123
def get_window_extent (self , * args , ** kwargs ):
1114
- 'return a extent of the legend'
1124
+ 'Return extent of the legend. '
1115
1125
return self .legendPatch .get_window_extent (* args , ** kwargs )
1116
1126
1117
1127
def get_frame_on (self ):
1118
1128
"""
1119
- Get whether the legend box patch is drawn
1129
+ Get whether the legend box patch is drawn.
1120
1130
"""
1121
1131
return self ._drawFrame
1122
1132
@@ -1131,7 +1141,7 @@ def set_frame_on(self, b):
1131
1141
1132
1142
def get_bbox_to_anchor (self ):
1133
1143
"""
1134
- return the bbox that the legend will be anchored
1144
+ Return the bbox that the legend will be anchored.
1135
1145
"""
1136
1146
if self ._bbox_to_anchor is None :
1137
1147
return self .parent .bbox
@@ -1140,12 +1150,16 @@ def get_bbox_to_anchor(self):
1140
1150
1141
1151
def set_bbox_to_anchor (self , bbox , transform = None ):
1142
1152
"""
1143
- set the bbox that the legend will be anchored.
1153
+ Set the bbox that the legend will be anchored.
1154
+
1155
+ *bbox* can be
1156
+
1157
+ - A `~.BboxBase` instance
1158
+ - A tuple of ``(left, bottom, width, height)`` in the given transform
1159
+ (normalized axes coordinate if None)
1160
+ - A tuple of ``[left, bottom]`` where the width and height will be
1161
+ assumed to be zero.
1144
1162
1145
- *bbox* can be a BboxBase instance, a tuple of [left, bottom,
1146
- width, height] in the given transform (normalized axes
1147
- coordinate if None), or a tuple of [left, bottom] where the
1148
- width and height will be assumed to be zero.
1149
1163
"""
1150
1164
if bbox is None :
1151
1165
self ._bbox_to_anchor = None
@@ -1209,7 +1223,7 @@ def _find_best_position(self, width, height, renderer, consider=None):
1209
1223
"""
1210
1224
Determine the best location to place the legend.
1211
1225
1212
- ` consider` is a list of (x, y) pairs to consider as a potential
1226
+ * consider* is a list of `` (x, y)`` pairs to consider as a potential
1213
1227
lower-left corner of the legend. All are display coords.
1214
1228
"""
1215
1229
# should always hold because function is only called internally
@@ -1258,7 +1272,7 @@ def draggable(self, state=None, use_blit=False, update="loc"):
1258
1272
* False : turn draggable off
1259
1273
1260
1274
If draggable is on, you can drag the legend on the canvas with
1261
- the mouse. The DraggableLegend helper instance is returned if
1275
+ the mouse. The `~. DraggableLegend` helper instance is returned if
1262
1276
draggable is on.
1263
1277
1264
1278
The update parameter control which parameter of the legend changes
0 commit comments