.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/10-showcase-violin.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_10-showcase-violin.py: ==================== Violing Chart demonstraing various mpl-visual-context features ==================== .. GENERATED FROM PYTHON SOURCE LINES 7-117 .. image-sg:: /examples/images/sphx_glr_10-showcase-violin_001.png :alt: 10 showcase violin :srcset: /examples/images/sphx_glr_10-showcase-violin_001.png :class: sphx-glr-single-img .. code-block:: default # import numpy as np from mpl_visual_context.patheffects import AlphaGradient import matplotlib.pyplot as plt import mpl_visual_context.patheffects as pe import seaborn seaborn.set() tips = seaborn.load_dataset("tips") # We start from a simple seaborn violin plot fig, axs = plt.subplots(2, 2, num=1, clear=True, figsize=(8, 6), layout="constrained") for ax in axs.flat: seaborn.violinplot(x='day', y='tip', data=tips, ax=ax) ax = axs[0, 0] ax.annotate( "(a) Original violin plot", (0, 1), xytext=(5, -5), xycoords="axes fraction", va="top", ha="left", textcoords="offset points", # size=20, ) # (b) w/ Brighter fill color ax = axs[0, 1] # We select violin patches. colls = ax.collections[::2] ax.annotate( "(b) Make fill color lighter,\nand stroke with the (original) fill color", (0, 1), xytext=(5, -5), xycoords="axes fraction", va="top", ha="left", textcoords="offset points", # size=20, ) pe_list = [ pe.HLSModify(l=0.8) | pe.FillOnly(), pe.StrokeColorFromFillColor() | pe.StrokeOnly(), ] for x, coll in enumerate(colls): coll.set_path_effects(pe_list) # (c) AlphaGradient ax = axs[1, 0] colls = ax.collections[::2] ax.annotate( "(c) Fill w/ alpha gradient", (0, 1), xytext=(5, -5), xycoords="axes fraction", va="top", ha="left", textcoords="offset points", # size=20, ) pe_list = [ pe.AlphaGradient("0.8 > 0.2 > 0.8"), (pe.StrokeColorFromFillColor() | pe.StrokeOnly()), ] for x, coll in enumerate(colls): coll.set_path_effects(pe_list) # (4) w/ Light effect ax = axs[1, 1] colls = ax.collections[::2] ax.annotate( "(d) Light effect and shadow", (0, 1), xytext=(5, -5), xycoords="axes fraction", va="top", ha="left", textcoords="offset points", # size=20, ) import mpl_visual_context.image_effect as ie pe_list = [ # shadow pe.FillOnly() | pe.ImageEffect( ie.AlphaAxb((0.5, 0)) | ie.Pad(10) | ie.Fill("k") | ie.Dilation(3) | ie.Gaussian(4) | ie.Offset(3, -3) ), # light effect pe.HLSModify(l=0.7) | pe.FillOnly() | pe.ImageEffect(ie.LightSource(erosion_size=5, gaussian_size=5)), ] for x, coll in enumerate(colls): coll.set_path_effects(pe_list) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.310 seconds) .. _sphx_glr_download_examples_10-showcase-violin.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 10-showcase-violin.py <10-showcase-violin.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 10-showcase-violin.ipynb <10-showcase-violin.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_