@@ -178,8 +178,10 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
178178 Whether round edges should be enabled around the `.FancyBboxPatch` which
179179 makes up the legend's background.
180180
181- shadow : bool, default: :rc:`legend.shadow`
181+ shadow : None, bool or dict , default: :rc:`legend.shadow`
182182 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.
183185
184186framealpha : float, default: :rc:`legend.framealpha`
185187 The alpha transparency of the legend's background.
@@ -558,6 +560,22 @@ def val_or_rc(val, rc_name):
558560 self ._mode = mode
559561 self .set_bbox_to_anchor (bbox_to_anchor , bbox_transform )
560562
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+
561579 # We use FancyBboxPatch to draw a legend frame. The location
562580 # and size of the box will be updated during the drawing time.
563581
@@ -743,8 +761,11 @@ def draw(self, renderer):
743761 self .legendPatch .set_bounds (bbox .bounds )
744762 self .legendPatch .set_mutation_scale (fontsize )
745763
764+ # self.shadow is validated in __init__
765+ # So by here it is a bool and self._shadow_props contains any configs
766+
746767 if self .shadow :
747- Shadow (self .legendPatch , 2 , - 2 ).draw (renderer )
768+ Shadow (self .legendPatch , ** self . _shadow_props ).draw (renderer )
748769
749770 self .legendPatch .draw (renderer )
750771 self ._legend_box .draw (renderer )
0 commit comments