8000 Add configuration of Shadow and pie shadow · matplotlib/matplotlib@95e1383 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95e1383

Browse files
committed
Add configuration of Shadow and pie shadow
1 parent 7c07acf commit 95e1383

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The pie chart shadow can be controlled
2+
--------------------------------------
3+
4+
The *shadow* argument to `~.Axes.pie` can now be a dict, allowing more control
5+
of the `.Shadow`-patch used.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Shadow shade can be controlled
2+
------------------------------
3+
4+
The `.Shadow` patch now has a *shade* argument to control the shadow darkness.
5+
If 0, the shadow is black, if 1, the shadow has the same color as the patch that
6+
is shadowed. The default value, which earlier was fixed, is 0.3.

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,8 +3126,12 @@ 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`.
3132+
3133+
.. versionadded:: 3.8
3134+
*shadow* can be a dict.
31313135
31323136
startangle : float, default: 0 degrees
31333137
The angle by which the start of the pie is rotated,
@@ -3255,8 +3259,10 @@ def get_next_color():
32553259
if shadow:
32563260
# Make sure to add a shadow after the call to add_patch so the
32573261
# figure and transform props will be set.
3258-
shad = mpatches.Shadow(w, -0.02, -0.02, label='_nolegend_')
3259-
self.add_patch(shad)
3262+
shadow_dict = {'ox': -0.02, 'oy': -0.02, 'label': '_nolegend_'}
3263+
if isinstance(shadow, dict):
3264+
shadow_dict.update(shadow)
3265+
self.add_patch(mpatches.Shadow(w, **shadow_dict))
32603266

32613267
if labeldistance is not None:
32623268
xt = x + labeldistance * radius * math.cos(thetam)

lib/matplotlib/patches.py

Lines changed: 11 additions & 3 deletions
< 8000 td data-grid-cell-id="diff-03b74bfefbb7d4eca2804f274825899d191f8bacdbe99ea973d88925f15d1169-631-635-2" data-line-anchor="diff-03b74bfefbb7d4eca2804f274825899d191f8bacdbe99ea973d88925f15d1169R635" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell pt-4 left-side">+
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,12 @@ 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*.
635
636+
.. versionadded:: 3.8
637+
632638
**kwargs
633639
Properties of the shadow patch. Supported keys are:
634640
@@ -640,7 +646,9 @@ def __init__(self, patch, ox, oy, **kwargs):
640646
self._shadow_transform = transforms.Affine2D()
641647

642648
self.update_from(self.patch)
643-
color = .3 * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
649+
if not 0 <= shade <= 1:
650+
raise ValueError("shade must be between 0 and 1.")
651+
color = shade * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
644652
self.update({'facecolor': color, 'edgecolor': color, 'alpha': 0.5,
645653
# Place shadow patch directly behind the inherited patch.
646654
'zorder': np.nextafter(self.patch.zorder, -np.inf),

0 commit comments

Comments
 (0)
0