.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/demo_bar_with_modified_path.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_with_modified_path.py: ============== Barchart with modified path ============== .. GENERATED FROM PYTHON SOURCE LINES 7-63 .. image-sg:: /examples/images/sphx_glr_demo_bar_with_modified_path_001.png :alt: demo bar with modified path :srcset: /examples/images/sphx_glr_demo_bar_with_modified_path_001.png :class: sphx-glr-single-img .. code-block:: Python import mpl_visual_context.patheffects as pe import numpy as np import matplotlib.pyplot as plt # Fixing random state for reproducibility np.random.seed(19680) # Example data n = 4 x_pos = np.arange(n) performance = 5 * np.random.rand(n) colors = [f"C{i}" for i in range(n)] fig, axs = plt.subplots(2, 2, num=1, clear=True) ax = axs.flat[0] bars = ax.bar(x_pos, performance, align='center', alpha=0.7, color=colors) ax = axs.flat[1] bars = ax.bar(x_pos, performance, align='center', alpha=0.7, color=colors) patheffects = [pe.RoundCorner(10, i_selector=lambda i: i in [2, 3]) | pe.AlphaGradient("0.2 ^ 1.")] for p in bars: p.set_path_effects(patheffects) from mpl_pe_fancy_bar import BarToArrow ax = axs.flat[2] bars = ax.bar(x_pos, performance, align='center', alpha=0.7, color=colors) patheffects = [BarToArrow() | pe.AlphaGradient("0.2 ^ 1.")] for p in bars: p.set_path_effects(patheffects) from mpl_pe_fancy_bar import BarTransformBase, BarToRoundBar from matplotlib.path import Path class CustomBar(BarTransformBase): def __init__(self, radius=0.3, orientation="vertical"): super().__init__(orientation=orientation) self._radius = radius def _get_surface(self, h): circle = Path.circle(center=(0., h-0.5), radius=0.3) return circle ax = axs.flat[3] bars = ax.bar(x_pos, performance, align='center', alpha=0.7, color=colors) patheffects = [ BarToRoundBar() | pe.AlphaGradient("0.2 ^ 1."), pe.FillColor("w") | CustomBar(), ] for p in bars: p.set_path_effects(patheffects) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.235 seconds) .. _sphx_glr_download_examples_demo_bar_with_modified_path.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_with_modified_path.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_bar_with_modified_path.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_bar_with_modified_path.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_