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()
import matplotlib.pyplot as plt
import numpy as np
b = np.diag(range(15))
_, ax = plt.subplots()
ax.matshow(b, cmap='binary')
plt.show()
Pythonic Programming © 2024
Built by Gavin Wiggins