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

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

.. _sphx_glr_gallery_lines_bars_and_markers_nan_test.py:


========
Nan Test
========

Example: simple line plots with NaNs inserted.




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





.. code-block:: python

    import numpy as np
    import matplotlib.pyplot as plt

    t = np.arange(0.0, 1.0 + 0.01, 0.01)
    s = np.cos(2 * 2*np.pi * t)
    t[41:60] = np.nan

    plt.subplot(2, 1, 1)
    plt.plot(t, s, '-', lw=2)

    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('A sine wave with a gap of NaNs between 0.4 and 0.6')
    plt.grid(True)

    plt.subplot(2, 1, 2)
    t[0] = np.nan
    t[-1] = np.nan
    plt.plot(t, s, '-', lw=2)
    plt.title('Also with NaN in first and last point')

    plt.xlabel('time (s)')
    plt.ylabel('more nans')
    plt.grid(True)

    plt.tight_layout()
    plt.show()


.. _sphx_glr_download_gallery_lines_bars_and_markers_nan_test.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: nan_test.ipynb <nan_test.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>`_
