.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_numpy_auto_examples_plot_elephant.py: Reading and writing an elephant =============================== Read and write images .. code-block:: python import numpy as np import matplotlib.pyplot as plt original figure ################################ .. code-block:: python plt.figure() img = plt.imread('../../../data/elephant.png') plt.imshow(img) .. image:: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_001.png :class: sphx-glr-single-img red channel displayed in grey ################################ .. code-block:: python plt.figure() img_red = img[:, :, 0] plt.imshow(img_red, cmap=plt.cm.gray) .. image:: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_002.png :class: sphx-glr-single-img lower resolution ################################ .. code-block:: python plt.figure() img_tiny = img[::6, ::6] plt.imshow(img_tiny, interpolation='nearest') plt.show() .. image:: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_003.png :class: sphx-glr-single-img **Total running time of the script:** ( 0 minutes 0.038 seconds) .. _sphx_glr_download_intro_numpy_auto_examples_plot_elephant.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_elephant.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_elephant.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_