.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/image-box/barh_cmap.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_image-box_barh_cmap.py: ==================== Horizontal bar chart w/ Gradient ==================== This example is based on barh.py example from matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 8-60 .. image-sg:: /examples/image-box/images/sphx_glr_barh_cmap_001.png :alt: How fast do you want to go today?, How fast do you want to go today? :srcset: /examples/image-box/images/sphx_glr_barh_cmap_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np # import seaborn as sns # sns.set_theme() import mplcyberpunk plt.style.use("cyberpunk") # Fixing random state for reproducibility np.random.seed(19680801) fig, axs = plt.subplots(1, 2, num=1, clear=True, layout="constrained") # Example data people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim') y_pos = np.arange(len(people)) performance = 3 + 10 * np.random.rand(len(people)) error = np.random.rand(len(people)) def draw_ax(ax): bars = ax.barh(y_pos, performance, xerr=error, align='center') ax.set_yticks(y_pos, labels=people) ax.invert_yaxis() # labels read top-to-bottom ax.set_xlabel('Performance') ax.set_title('How fast do you want to go today?') return bars from mpl_visual_context.patheffects import FillImage, AlphaGradient from mpl_visual_context.image_box import ImageBox ax = axs[0] bars = draw_ax(ax) pe = [AlphaGradient("right")] for p in bars: p.set_path_effects(pe) ax = axs[1] bars = draw_ax(ax) bbox_image = ImageBox("right", alpha="right", extent=[0, 0, 1.0, 1], coords=bars) pe = [FillImage(bbox_image, ax=ax)] for p in bars: p.set_path_effects(pe) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.207 seconds) .. _sphx_glr_download_examples_image-box_barh_cmap.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: barh_cmap.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: barh_cmap.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: barh_cmap.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_