@@ -178,8 +178,10 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
178
178
Whether round edges should be enabled around the `.FancyBboxPatch` which
179
179
makes up the legend's background.
180
180
181
- shadow : bool, default: :rc:`legend.shadow`
181
+ shadow : None, bool or dict , default: :rc:`legend.shadow`
182
182
Whether to draw a shadow behind the legend.
183
+ The shadow can be configured using `.Patch` keywords.
184
+ Customization via :rc:`legend.shadow` is currently not supported.
183
185
184
186
framealpha : float, default: :rc:`legend.framealpha`
185
187
The alpha transparency of the legend's background.
@@ -558,6 +560,22 @@ def val_or_rc(val, rc_name):
558
560
self ._mode = mode
559
561
self .set_bbox_to_anchor (bbox_to_anchor , bbox_transform )
560
562
563
+ # Figure out if self.shadow is valid
564
+ # If shadow was None, rcParams loads False
565
+ # So it shouldn't be None here
566
+
567
+ self ._shadow_props = {'ox' : 2 , 'oy' : - 2 } # default location offsets
568
+ if isinstance (self .shadow , dict ):
569
+ self ._shadow_props .update (self .shadow )
570
+ self .shadow = True
571
+ elif self .shadow in (0 , 1 , True , False ):
572
+ self .shadow = bool (self .shadow )
573
+ else :
574
+ raise ValueError (
575
+ 'Legend shadow must be a dict or bool, not '
576
+ f'{ self .shadow !r} of type { type (self .shadow )} .'
577
+ )
578
+
561
579
# We use FancyBboxPatch to draw a legend frame. The location
562
580
# and size of the box will be updated during the drawing time.
563
581
@@ -743,8 +761,11 @@ def draw(self, renderer):
743
761
self .legendPatch .set_bounds (bbox .bounds )
744
762
self .legendPatch .set_mutation_scale (fontsize )
745
763
764
+ # self.shadow is validated in __init__
765
+ # So by here it is a bool and self._shadow_props contains any configs
766
+
746
767
if self .shadow :
747
- Shadow (self .legendPatch , 2 , - 2 ).draw (renderer )
768
+ Shadow (self .legendPatch , ** self . _shadow_props ).draw (renderer )
748
769
749
770
self .legendPatch .draw (renderer )
750
771
self ._legend_box .draw (renderer )
0 commit comments