@@ -63,7 +63,7 @@ class Legend(Artist):
63
63
64
64
loc can be a tuple of the noramilzed coordinate values with
65
65
respect its parent.
66
-
66
+
67
67
Return value is a sequence of text, line instances that make
68
68
up the legend
69
69
"""
@@ -94,15 +94,15 @@ def __init__(self, parent, handles, labels,
94
94
scatterpoints = 3 , # TODO: may be an rcParam
95
95
scatteryoffsets = None ,
96
96
prop = None , # properties for the legend texts
97
-
97
+
98
98
# the following dimensions are in axes coords
99
99
pad = None , # deprecated; use borderpad
100
- labelsep = None , # deprecated; use labelspacing
101
- handlelen = None , # deprecated; use handlelength
102
- handletextsep = None , # deprecated; use handletextpad
100
+ labelsep = None , # deprecated; use labelspacing
101
+ handlelen = None , # deprecated; use handlelength
102
+ handletextsep = None , # deprecated; use handletextpad
103
103
axespad = None , # deprecated; use borderaxespad
104
104
105
- # spacing & pad defined as a fractionof the font-size
105
+ # spacing & pad defined as a fractionof the font-size
106
106
borderpad = None , # the whitespace inside the legend border
107
107
labelspacing = None , #the vertical space between the legend entries
108
108
handlelength = None , # the length of the legend handles
@@ -113,7 +113,7 @@ def __init__(self, parent, handles, labels,
113
113
ncol = 1 , # number of columns
114
114
mode = None , # mode for horizontal distribution of columns. None, "expand"
115
115
116
- fancybox = True ,
116
+ fancybox = None , # True use a fancy box, false use a rounded box, none use rc
117
117
shadow = None ,
118
118
):
119
119
"""
@@ -131,7 +131,7 @@ def __init__(self, parent, handles, labels,
131
131
numpoints the number of points in the legend line
132
132
prop the font property
133
133
markerscale the relative size of legend markers vs. original
134
- fancybox if True, draw a frame with a round fancybox.
134
+ fancybox if True, draw a frame with a round fancybox. If None, use rc
135
135
shadow if True, draw a shadow behind legend
136
136
scatteryoffsets a list of yoffsets for scatter symbols in legend
137
137
@@ -144,7 +144,7 @@ def __init__(self, parent, handles, labels,
144
144
145
145
The dimensions of pad and spacing are given as a fraction of the
146
146
fontsize. Values from rcParams will be used if None.
147
-
147
+
148
148
"""
149
149
from matplotlib .axes import Axes # local import only to avoid circularity
150
150
from matplotlib .figure import Figure # local import only to avoid circularity
@@ -172,7 +172,7 @@ def __init__(self, parent, handles, labels,
172
172
# Take care the deprecated keywords
173
173
deprecated_kwds = {"pad" :"borderpad" ,
174
174
"labelsep" :"labelspacing" ,
175
- "handlelen" :"handlelength" ,
175
+ "handlelen" :"handlelength" ,
176
176
"handletextsep" :"handletextpad" ,
177
177
"axespad" :"borderaxespad" }
178
178
@@ -182,7 +182,7 @@ def __init__(self, parent, handles, labels,
182
182
# conversion factor
183
183
bbox = parent .bbox
184
184
axessize_fontsize = min (bbox .width , bbox .height )/ self .fontsize
185
-
185
+
186
186
for k , v in deprecated_kwds .items ():
187
187
# use deprecated value if not None and if their newer
188
188
# counter part is None.
@@ -199,7 +199,7 @@ def __init__(self, parent, handles, labels,
199
199
setattr (self , v , localdict [v ])
200
200
201
201
del localdict
202
-
202
+
203
203
self ._ncol = ncol
204
204
205
205
if self .numpoints <= 0 :
@@ -265,6 +265,9 @@ def __init__(self, parent, handles, labels,
265
265
# The width and height of the legendPatch will be set (in the
266
266
# draw()) to the length that includes the padding. Thus we set
267
267
# pad=0 here.
268
+ if fancybox is None :
269
+ fancybox = rcParams ["legend.fancybox" ]
270
+
268
271
if fancybox == True :
269
272
self .legendPatch .set_boxstyle ("round" ,pad = 0 ,
270
273
rounding_size = 0.2 )
@@ -318,7 +321,7 @@ def draw(self, renderer):
318
321
319
322
# find_offset function will be provided to _legend_box and
320
323
# _legend_box will draw itself at the location of the return
321
- # value of the find_offset.
324
+ # value of the find_offset.
322
325
if self ._loc == 0 :
323
326
self ._legend_box .set_offset (self ._findoffset_best )
324
327
else :
@@ -339,7 +342,7 @@ def draw(self, renderer):
339
342
if self .shadow :
340
343
shadow = Shadow (self .legendPatch , 2 , - 2 )
341
344
shadow .draw (renderer )
342
-
345
+
343
346
self .legendPatch .draw (renderer )
344
347
345
348
self ._legend_box .draw (renderer )
@@ -360,7 +363,7 @@ def _init_legend_box(self, handles, labels):
360
363
Initiallize the legend_box. The legend_box is an instance of
361
364
the OffsetBox, which is packed with legend handles and
362
365
texts. Once packed, their location is calculated during the
363
- drawing time.
366
+ drawing time.
364
367
"""
365
368
366
369
# legend_box is a HPacker, horizontally packed with
@@ -371,7 +374,7 @@ def _init_legend_box(self, handles, labels):
371
374
# is an instance of offsetbox.TextArea which contains legend
372
375
# text.
373
376
374
-
377
+
375
378
text_list = [] # the list of text instances
376
379
handle_list = [] # the list of text instances
377
380
@@ -394,12 +397,12 @@ def _init_legend_box(self, handles, labels):
394
397
# The approximate height and descent of text. These values are
395
398
# only used for plotting the legend handle.
396
399
height = self ._approx_text_height () * 0.7
397
- descent = 0.
400
+ descent = 0.
398
401
399
402
# each handle needs to be drawn inside a box of
400
403
# (x, y, w, h) = (0, -descent, width, height).
401
404
# And their corrdinates should be given in the display coordinates.
402
-
405
+
403
406
# The transformation of each handle will be automatically set
404
407
# to self.get_trasnform(). If the artist does not uses its
405
408
# default trasnform (eg, Collections), you need to
@@ -413,7 +416,7 @@ def _init_legend_box(self, handles, labels):
413
416
if npoints > 1 :
414
417
# we put some pad here to compensate the size of the
415
418
# marker
416
- xdata = np .linspace (0.3 * self .fontsize ,
419
+ xdata = np .linspace (0.3 * self .fontsize ,
417
420
(self .handlelength - 0.3 )* self .fontsize ,
418
421
npoints )
419
422
xdata_marker = xdata
@@ -484,14 +487,14 @@ def _init_legend_box(self, handles, labels):
484
487
size_min ]
485
488
else :
486
489
sizes = (size_max - size_min )* np .linspace (0 ,1 ,self .scatterpoints )+ size_min
487
-
490
+
488
491
p = type (handle )(handle .get_numsides (),
489
492
rotation = handle .get_rotation (),
490
493
sizes = sizes ,
491
494
offsets = zip (xdata_marker ,ydata ),
492
495
transOffset = self .get_transform (),
493
496
)
494
-
497
+
495
498
p .update_from (handle )
496
499
p .set_figure (self .figure )
497
500
p .set_clip_box (None )
@@ -534,7 +537,7 @@ def _init_legend_box(self, handles, labels):
534
537
for h , t in handle_label [i0 :i0 + di ]]
535
538
# minimumdescent=False for the text of the last row of the column
536
539
itemBoxes [- 1 ].get_children ()[1 ].set_minimumdescent (False )
537
-
540
+
538
541
# pack columnBox
539
542
columnbox .append (VPacker (pad = 0 ,
540
543
sep = self .labelspacing * self .fontsize ,
@@ -547,15 +550,15 @@ def _init_legend_box(self, handles, labels):
547
550
mode = "fixed"
548
551
549
552
sep = self .columnspacing * self .fontsize
550
-
553
+
551
554
self ._legend_box = HPacker (pad = self .borderpad * self .fontsize ,
552
555
sep = sep , align = "baseline" ,
553
556
mode = mode ,
554
557
children = columnbox )
555
558
556
559
self .texts = text_list
557
560
self .legendHandles = handle_list
558
-
561
+
559
562
560
563
def _auto_legend_data (self ):
561
564
"""
@@ -655,12 +658,12 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox):
655
658
LC :"S" ,
656
659
UC :"N" ,
657
660
C :"C" }
658
-
661
+
659
662
c = anchor_coefs [loc ]
660
663
661
664
container = parentbbox .padded (- (self .borderaxespad ) * self .fontsize )
662
665
anchored_box = bbox .anchored (c , container = container )
663
- return anchored_box .x0 , anchored_box .y0
666
+ return anchored_box .x0 , anchored_box .y0
664
667
665
668
666
669
def _find_best_position (self , width , height , consider = None ):
0 commit comments