.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "seismo/matplotlib/chist.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_seismo_matplotlib_chist.py: Colored histogram ------------------ This is en example of histogram with colored bars. .. GENERATED FROM PYTHON SOURCE LINES 7-39 .. image-sg:: /seismo/matplotlib/images/sphx_glr_chist_001.png :alt: chist :srcset: /seismo/matplotlib/images/sphx_glr_chist_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/micromamba/envs/docs/lib/python3.12/site-packages/scikits/__init__.py:1: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. __import__("pkg_resources").declare_namespace(__name__) | .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from scipy import stats from matplotlib import colors def plot(nsamp=5000): rng = np.random.default_rng(19680801) dist = rng.standard_normal(nsamp) fig, ax = plt.subplots() ax.grid() N, bins, patches = ax.hist(dist, bins=40) fracs = N / N.max() norm = colors.Normalize(fracs.min(), fracs.max()) for thisfrac, thispatch in zip(fracs, patches): color = plt.cm.Blues(norm(thisfrac)) thispatch.set_facecolor(color) mean = np.mean(dist) std = np.std(dist) ci = stats.norm.interval(0.90, loc=mean, scale=std) ax.text(0.01, 0.99, "90% Confidence interval = [{:.3f}, {:.3f}]".format(*ci), size=8, va='top', ha='left', transform=ax.transAxes, bbox=dict(boxstyle="round", ec=(0.5, 0.5, 0.5), fc=(0.9, 0.9, 0.9), ) ) ax.set_ylabel('Count') if __name__ == '__main__': plot() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.647 seconds) .. _sphx_glr_download_seismo_matplotlib_chist.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: chist.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: chist.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: chist.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_