.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/lines_bars_and_markers/span_regions.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. 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_gallery_lines_bars_and_markers_span_regions.py: ========================================================== Shade regions defined by a logical mask using fill_between ========================================================== .. GENERATED FROM PYTHON SOURCE LINES 6-24 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np t = np.arange(0.0, 2, 0.01) s = np.sin(2*np.pi*t) fig, ax = plt.subplots() ax.plot(t, s, color='black') ax.axhline(0, color='black') ax.fill_between(t, 1, where=s > 0, facecolor='green', alpha=.5) ax.fill_between(t, -1, where=s < 0, facecolor='red', alpha=.5) plt.show() .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_span_regions_001.png :alt: span regions :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_span_regions_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_span_regions_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.axes.Axes.fill_between` .. _sphx_glr_download_gallery_lines_bars_and_markers_span_regions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: span_regions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: span_regions.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_