.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_lines_bars_and_markers_fill.py: ============== Fill plot demo ============== Demo fill plot. First, the most basic fill plot a user can make with matplotlib: .. code-block:: python import numpy as np import matplotlib.pyplot as plt x = [0, 1, 2, 1] y = [1, 2, 1, 0] fig, ax = plt.subplots() ax.fill(x, y) plt.show() .. image:: /gallery/lines_bars_and_markers/images/sphx_glr_fill_001.png :class: sphx-glr-single-img Next, a few more optional features: * Multiple curves with a single command. * Setting the fill color. * Setting the opacity (alpha value). .. code-block:: python x = np.linspace(0, 1.5 * np.pi, 500) y1 = np.sin(x) y2 = np.sin(3 * x) fig, ax = plt.subplots() ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3) # Outline of the region we've filled in ax.plot(x, y1, c='b', alpha=0.8) ax.plot(x, y2, c='r', alpha=0.8) ax.plot([x[0], x[-1]], [y1[0], y1[-1]], c='b', alpha=0.8) ax.plot([x[0], x[-1]], [y2[0], y2[-1]], c='r', alpha=0.8) plt.show() .. image:: /gallery/lines_bars_and_markers/images/sphx_glr_fill_002.png :class: sphx-glr-single-img .. _sphx_glr_download_gallery_lines_bars_and_markers_fill.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: fill.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: fill.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_