Note
Go to the end to download the full example code
Violing Chart w/ ImageEffects

/home/docs/checkouts/readthedocs.org/user_builds/mpl-visual-context/envs/0.9.2/lib/python3.10/site-packages/seaborn/_oldcore.py:1498: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if pd.api.types.is_categorical_dtype(vector):
/home/docs/checkouts/readthedocs.org/user_builds/mpl-visual-context/envs/0.9.2/lib/python3.10/site-packages/seaborn/categorical.py:641: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
grouped_vals = vals.groupby(grouper)
import numpy as np
import matplotlib.pyplot as plt
import seaborn
seaborn.set()
tips = seaborn.load_dataset("tips")
fig, ax = plt.subplots(num=1, clear=True)
seaborn.violinplot(x='day', y='tip', data=tips, ax=ax)
from matplotlib.collections import PolyCollection
import mpl_visual_context.patheffects as pe
import mpl_visual_context.image_effect as ie
colls = [p for p in ax.collections if isinstance(p, PolyCollection)]
shadow = pe.ImageEffect(
ie.AlphaAxb((0.3, 0))
| ie.Pad(10)
| ie.Fill("k")
| ie.Dilation(3)
| ie.Gaussian(4)
| ie.Offset(3, -3)
)
light = pe.ImageEffect(ie.LightSource(erosion_size=5, gaussian_size=5))
pe_list = [pe.FillOnly() | shadow, pe.FillOnly() | light]
for x, coll in enumerate(colls):
coll.set_path_effects(pe_list)
plt.show()
Total running time of the script: (0 minutes 0.249 seconds)