.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/lines_bars_and_markers/fill_betweenx_demo.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_fill_betweenx_demo.py: ================== Fill Betweenx Demo ================== Using `~.Axes.fill_betweenx` to color along the horizontal direction between two curves. .. GENERATED FROM PYTHON SOURCE LINES 9-28 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np y = np.arange(0.0, 2, 0.01) x1 = np.sin(2 * np.pi * y) x2 = 1.2 * np.sin(4 * np.pi * y) fig, [ax1, ax2, ax3] = plt.subplots(1, 3, sharey=True, figsize=(6, 6)) ax1.fill_betweenx(y, 0, x1) ax1.set_title('between (x1, 0)') ax2.fill_betweenx(y, x1, 1) ax2.set_title('between (x1, 1)') ax2.set_xlabel('x') ax3.fill_betweenx(y, x1, x2) ax3.set_title('between (x1, x2)') .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_fill_betweenx_demo_001.png :alt: between (x1, 0), between (x1, 1), between (x1, x2) :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_fill_betweenx_demo_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_fill_betweenx_demo_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-35 Now fill between x1 and x2 where a logical condition is met. Note this is different than calling:: fill_between(y[where], x1[where], x2[where]) because of edge effects over multiple contiguous regions. .. GENERATED FROM PYTHON SOURCE LINES 35-49 .. code-block:: Python fig, [ax, ax1] = plt.subplots(1, 2, sharey=True, figsize=(6, 6)) ax.plot(x1, y, x2, y, color='black') ax.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green') ax.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red') ax.set_title('fill_betweenx where') # Test support for masked arrays. x2 = np.ma.masked_greater(x2, 1.0) ax1.plot(x1, y, x2, y, color='black') ax1.fill_betweenx(y, x1, x2, where=x2 >= x1, facecolor='green') ax1.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red') ax1.set_title('regions with x2 > 1 are masked') .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_fill_betweenx_demo_002.png :alt: fill_betweenx where, regions with x2 > 1 are masked :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_fill_betweenx_demo_002.png, /gallery/lines_bars_and_markers/images/sphx_glr_fill_betweenx_demo_002_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-53 This example illustrates a problem; because of the data gridding, there are undesired unfilled triangles at the crossover points. A brute-force solution would be to interpolate all arrays to a very fine grid before plotting. .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.079 seconds) .. _sphx_glr_download_gallery_lines_bars_and_markers_fill_betweenx_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fill_betweenx_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fill_betweenx_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_