Skip to content

Fix pie chart in demo_agg_filter.py #24261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions examples/misc/demo_agg_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,19 @@ def process_image(self, padded_src, dpi):


class LightFilter(BaseFilter):

def __init__(self, sigma, fraction=0.5):
"""Apply LightSource filter"""

def __init__(self, sigma, fraction=1):
"""
Parameters
----------
sigma : float
sigma for gaussian filter
fraction: number, default: 1
Increases or decreases the contrast of the hillshade.
See `matplotlib.colors.LightSource`

"""
self.gauss_filter = GaussianFilter(sigma, alpha=1)
self.light_source = LightSource()
self.fraction = fraction
Expand All @@ -114,7 +125,8 @@ def process_image(self, padded_src, dpi):
rgb = padded_src[:, :, :3]
alpha = padded_src[:, :, 3:]
rgb2 = self.light_source.shade_rgb(rgb, elevation,
fraction=self.fraction)
fraction=self.fraction,
blend_mode="overlay")
return np.concatenate([rgb2, alpha], -1)


Expand Down Expand Up @@ -257,7 +269,7 @@ def drop_shadow_patches(ax):

def light_filter_pie(ax):
fracs = [15, 30, 45, 10]
explode = (0, 0.05, 0, 0)
explode = (0.1, 0.2, 0.1, 0.1)
pies = ax.pie(fracs, explode=explode)

light_filter = LightFilter(9)
Expand All @@ -267,7 +279,7 @@ def light_filter_pie(ax):
p.set(ec="none",
lw=2)

gauss = DropShadowFilter(9, offsets=(3, 4), alpha=0.7)
gauss = DropShadowFilter(9, offsets=(3, -4), alpha=0.7)
shadow = FilteredArtistList(pies[0], gauss)
ax.add_artist(shadow)
shadow.set_zorder(pies[0][0].get_zorder() - 0.1)
Expand Down