Gavin Wiggins

AboutNotesPhotos


Matshow plot

Written on May 10, 2023

Visualize an array using Matplotlib's matshow function. The first example shown below plots a 2D array and the second example plots a diagonal array.

import matplotlib.pyplot as plt
import numpy as np

a = np.random.rand(20, 20)

fig, ax = plt.subplots()
im = ax.matshow(a)
fig.colorbar(im, ax=ax)

plt.show()

matshow plot

import matplotlib.pyplot as plt
import numpy as np

b = np.diag(range(15))

_, ax = plt.subplots()
ax.matshow(b, cmap='binary')

plt.show()

matshow plot

Gavin Wiggins © 2024.
Made on a Mac with Genja. Hosted on GitHub Pages.