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

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

.. _sphx_glr_gallery_specialty_plots_mri_demo.py:


===
MRI
===


This example illustrates how to read an image (of an MRI) into a NumPy
array, and display it in greyscale using `imshow`.





.. image:: /gallery/specialty_plots/images/sphx_glr_mri_demo_001.png
    :class: sphx-glr-single-img





.. code-block:: python


    import matplotlib.pyplot as plt
    import matplotlib.cbook as cbook
    import matplotlib.cm as cm
    import numpy as np


    # Data are 256x256 16 bit integers
    with cbook.get_sample_data('s1045.ima.gz') as dfile:
        im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))

    fig, ax = plt.subplots(num="MRI_demo")
    ax.imshow(im, cmap=cm.gray)
    ax.axis('off')

    plt.show()


.. _sphx_glr_download_gallery_specialty_plots_mri_demo.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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