.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_gallery_lines_bars_and_markers_masked_demo.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_masked_demo.py:


===========
Masked Demo
===========

Plot lines with points masked out.

This would typically be used with gappy data, to
break the line at the data gaps.




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_masked_demo_001.png
    :class: sphx-glr-single-img





.. code-block:: python


    import matplotlib.pyplot as plt
    import numpy as np

    x = np.arange(0, 2*np.pi, 0.02)
    y = np.sin(x)
    y1 = np.sin(2*x)
    y2 = np.sin(3*x)
    ym1 = np.ma.masked_where(y1 > 0.5, y1)
    ym2 = np.ma.masked_where(y2 < -0.5, y2)

    lines = plt.plot(x, y, x, ym1, x, ym2, 'o')
    plt.setp(lines[0], linewidth=4)
    plt.setp(lines[1], linewidth=2)
    plt.setp(lines[2], markersize=10)

    plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'),
               loc='upper right')
    plt.title('Masked line demo')
    plt.show()


.. _sphx_glr_download_gallery_lines_bars_and_markers_masked_demo.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: masked_demo.py <masked_demo.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: masked_demo.ipynb <masked_demo.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
