.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/demo_bar_shadow.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_demo_bar_shadow.py: ============== HorizontalBarchart with shadows ============== .. GENERATED FROM PYTHON SOURCE LINES 7-21 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from matplotlib.patheffects import Normal # Fixing random state for reproducibility np.random.seed(19680) # Example data n = 5 x_pos = np.arange(n) performance = 5 * np.random.rand(n) colors = [f"C{i}" for i in range(n)] .. GENERATED FROM PYTHON SOURCE LINES 22-63 .. code-block:: Python fig, ax = plt.subplots(num=1, clear=True) bars = ax.barh(x_pos, performance, align='center', alpha=0.7, color=colors) ax.set_xlim(0, 2.8) from matplotlib.path import Path import mpl_visual_context.patheffects as pe from mpl_visual_context.patheffects_shadow import ShadowPath from mpl_pe_fancy_bar import BarTransformBase, BarToRoundBar from mpl_pe_fancy_bar.bar_with_icon import Icon, BarWithIcon circle = Path.unit_circle().copy() icon_circle = Icon((-1, -1, 2, 2), circle) bar_with_circle = BarWithIcon(icon_circle, scale=0.6, dh=0, orientation="horizontal") round_bar = BarToRoundBar(orientation="horizontal", dh=0) pe1 = [ round_bar| pe.AlphaGradient("0.4 > 0.8"), round_bar | pe.ClipPathSelf() | ShadowPath(135, 7) | pe.FillColor("k") | pe.GCModify(alpha=0.2), bar_with_circle | ShadowPath(135, 5) | pe.FillColor("k") | pe.GCModify(alpha=0.3), bar_with_circle | pe.GCModify(alpha=1) | pe.HLSModify(l=0.95), ] for p in bars: p.set_path_effects(pe1) for x, p in zip(x_pos, performance): ax.annotate(f"{p:.2f}", (p-0.1, x), va="center_baseline", ha="right", size=20, color="w") pe2 = [ ShadowPath(135, 5) | pe.HLSModify(l="20%") | pe.GCModify(alpha=0.5), pe.FillOnly() ] for t in ax.texts: t.set_path_effects(pe2) plt.show() .. image-sg:: /examples/images/sphx_glr_demo_bar_shadow_001.png :alt: demo bar shadow :srcset: /examples/images/sphx_glr_demo_bar_shadow_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mpl-pe-fancy-bar/envs/stable/lib/python3.10/site-packages/mpl_visual_context/bezier_helper.py:7: UserWarning: bezier module not fount. Using bezier-lite. warnings.warn("bezier module not fount. Using bezier-lite.") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.448 seconds) .. _sphx_glr_download_examples_demo_bar_shadow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_bar_shadow.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_bar_shadow.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_