.. 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 ` 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:: default import numpy as np import matplotlib.pyplot as plt data = np.loadtxt('../../../../data/populations.txt') populations = np.ma.masked_array(data[:,1:]) 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-python :download:`Download Python source code: plot_maskedstats.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_maskedstats.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_