.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/matplotlib/auto_examples/plot_bar.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_intro_matplotlib_auto_examples_plot_bar.py>` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_matplotlib_auto_examples_plot_bar.py: Bar plots ========== An example of bar plots with matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 7-33 .. image-sg:: /intro/matplotlib/auto_examples/images/sphx_glr_plot_bar_001.png :alt: plot bar :srcset: /intro/matplotlib/auto_examples/images/sphx_glr_plot_bar_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt n = 12 X = np.arange(n) rng = np.random.default_rng() Y1 = (1 - X / n) * rng.uniform(0.5, 1.0, n) Y2 = (1 - X / n) * rng.uniform(0.5, 1.0, n) plt.axes((0.025, 0.025, 0.95, 0.95)) plt.bar(X, +Y1, facecolor="#9999ff", edgecolor="white") plt.bar(X, -Y2, facecolor="#ff9999", edgecolor="white") for x, y in zip(X, Y1): plt.text(x, y + 0.05, f"{y:.2f}", ha="center", va="bottom") for x, y in zip(X, Y2): plt.text(x, -y - 0.05, f"{y:.2f}", ha="center", va="top") plt.xlim(-0.5, n) plt.xticks([]) plt.ylim(-1.25, 1.25) plt.yticks([]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.050 seconds) .. _sphx_glr_download_intro_matplotlib_auto_examples_plot_bar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_bar.ipynb <plot_bar.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_bar.py <plot_bar.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_bar.zip <plot_bar.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_