Visualizing a matrix with imshow

The following code compares two interpolation schemes, 'bilinear' (which, for a small array will make a blurry image) and 'nearest' which should look "blocky" (i.e. more faithful to the data).

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

# Make an array with ones in the shape of an 'X'
a = np.eye(10,10)
a += a[::-1,:]

fig = plt.figure()
ax1 = fig.add_subplot(121)
# Bilinear interpolation - this will look blurry
ax1.imshow(a, interpolation='bilinear', cmap=cm.Greys_r)

ax2 = fig.add_subplot(122)
# 'nearest' interpolation - faithful but blocky
ax2.imshow(a, interpolation='nearest', cmap=cm.Greys_r)

plt.show()

Matrix visualization

Note: in earlier versions of Matplotlib, bilinear interpolation was the default and interpolation='nearest' had to be set explicitly if required.