.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "advanced/advanced_numpy/auto_examples/plot_maskedstats.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_advanced_advanced_numpy_auto_examples_plot_maskedstats.py>` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_advanced_advanced_numpy_auto_examples_plot_maskedstats.py: Example: Masked statistics ========================== Plot a masked statistics .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. image-sg:: /advanced/advanced_numpy/auto_examples/images/sphx_glr_plot_maskedstats_001.png :alt: plot maskedstats :srcset: /advanced/advanced_numpy/auto_examples/images/sphx_glr_plot_maskedstats_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt data = np.loadtxt("../../../../data/populations.txt") populations = np.ma.masked_array(data[:, 1:]) # type: ignore[var-annotated] year = data[:, 0] bad_years = ((year >= 1903) & (year <= 1910)) | ((year >= 1917) & (year <= 1918)) populations[bad_years, 0] = np.ma.masked populations[bad_years, 1] = np.ma.masked plt.plot(year, populations, "o-") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.057 seconds) .. _sphx_glr_download_advanced_advanced_numpy_auto_examples_plot_maskedstats.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_maskedstats.ipynb <plot_maskedstats.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_maskedstats.py <plot_maskedstats.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_maskedstats.zip <plot_maskedstats.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_