You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Version 2.1.1.post1074+gb67098b
Fork me on GitHub

Related Topics

This Page


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

import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import 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(, np.uint16).reshape((256, 256))

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

Gallery generated by Sphinx-Gallery