Skip to content

Commit 23f9569

Browse files
committed
Add configuration of Shadow and pie shadow
1 parent 7c07acf commit 23f9569

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/matplotlib/axes/_axes.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -3126,8 +3126,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
31263126
If set to ``None``, labels are not drawn but are still stored for
31273127
use in `.legend`.
31283128
3129-
shadow : bool, default: False
3130-
Draw a shadow beneath the pie.
3129+
shadow : bool or dict, default: False
3130+
If bool, whether to draw a shadow beneath the pie. If dict, draw a shadow
3131+
passing the properties in the dict to `.Shadow`.
31313132
31323133
startangle : float, default: 0 degrees
31333134
The angle by which the start of the pie is rotated,
@@ -3255,7 +3256,11 @@ def get_next_color():
32553256
if shadow:
32563257
# Make sure to add a shadow after the call to add_patch so the
32573258
# figure and transform props will be set.
3258-
shad = mpatches.Shadow(w, -0.02, -0.02, label='_nolegend_')
3259+
shadow_dict = {
3260+
'ox': -0.02, 'oy': -0.02, 'shade': 0.3, 'label': '_nolegend_'}
3261+
if isinstance(shadow, dict):
3262+
shadow_dict.update(shadow)
3263+
shad = mpatches.Shadow(w, **shadow_dict)
32593264
self.add_patch(shad)
32603265

32613266
if labeldistance is not None:

lib/matplotlib/patches.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,12 @@ def __str__(self):
615615
return f"Shadow({self.patch})"
616616

617617
@_docstring.dedent_interpd
618-
def __init__(self, patch, ox, oy, **kwargs):
618+
def __init__(self, patch, ox, oy, *, shade=0.3, **kwargs):
619619
"""
620620
Create a shadow of the given *patch*.
621621
622622
By default, the shadow will have the same face color as the *patch*,
623-
but darkened.
623+
but darkened. The darkness can be controlled by *shade*.
624624
625625
Parameters
626626
----------
@@ -629,6 +629,9 @@ def __init__(self, patch, ox, oy, **kwargs):
629629
ox, oy : float
630630
The shift of the shadow in data coordinates, scaled by a factor
631631
of dpi/72.
632+
shade : float, default: 0.3
633+
How the darkness of the shadow relates to the original color. If 0, the
634+
shadow is black, if 1, the shadow has the same color as the *patch*.
632635
**kwargs
633636
Properties of the shadow patch. Supported keys are:
634637
@@ -640,7 +643,9 @@ def __init__(self, patch, ox, oy, **kwargs):
640643
self._shadow_transform = transforms.Affine2D()
641644

642645
self.update_from(self.patch)
643-
color = .3 * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
646+
if not 0 <= shade <= 1:
647+
raise ValueError("shade must be between 0 and 1.")
648+
color = shade * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
644649
self.update({'facecolor': color, 'edgecolor': color, 'alpha': 0.5,
645650
# Place shadow patch directly behind the inherited patch.
646651
'zorder': np.nextafter(self.patch.zorder, -np.inf),

0 commit comments

Comments
 (0)