.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/path_effects/barh_pe.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_path_effects_barh_pe.py: ==================== Horizontal bar chart ==================== This example is based on barh.py example from matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 8-47 .. image-sg:: /examples/path_effects/images/sphx_glr_barh_pe_001.png :alt: How fast do you want to go today? :srcset: /examples/path_effects/images/sphx_glr_barh_pe_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np # Fixing random state for reproducibility np.random.seed(19680801) fig, ax = plt.subplots() # 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)) 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?') # Now we pick Harry's bar and change its luminosity at 50 20%, and set # luminosity of others at 80%. from mpl_visual_context.patheffects import HLSModify, ColorMatrix pe_active = HLSModify(l="-80%") pe_inactive = HLSModify(l="-30%") | ColorMatrix("grayscale") for name, p in zip(people, bars.patches): if name == "Harry": p.set_path_effects([pe_active]) else: p.set_path_effects([pe_inactive]) # The plot also shows errorbar for each bar plot. The errorbar is represented # as a line_collection, and it is not straight forward to apply path_effects # only to the part of them. So, it it not attempted in this example. plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.058 seconds) .. _sphx_glr_download_examples_path_effects_barh_pe.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: barh_pe.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: barh_pe.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: barh_pe.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_