.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/numpy/auto_examples/plot_elephant.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_intro_numpy_auto_examples_plot_elephant.py: Reading and writing an elephant =============================== Read and write images .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: default import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 12-14 original figure ################################ .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: default plt.figure() img = plt.imread('../../../data/elephant.png') plt.imshow(img) .. image-sg:: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_001.png :alt: plot elephant :srcset: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 20-22 red channel displayed in grey ################################ .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: default plt.figure() img_red = img[:, :, 0] plt.imshow(img_red, cmap=plt.cm.gray) .. image-sg:: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_002.png :alt: plot elephant :srcset: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 28-30 lower resolution ################################ .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: default plt.figure() img_tiny = img[::6, ::6] plt.imshow(img_tiny, interpolation='nearest') plt.show() .. image-sg:: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_003.png :alt: plot elephant :srcset: /intro/numpy/auto_examples/images/sphx_glr_plot_elephant_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.241 seconds) .. _sphx_glr_download_intro_numpy_auto_examples_plot_elephant.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_elephant.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_elephant.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_