Heatmaps may be generated with imshow.
We import a colour map from the library cm.
For a list of colour maps available see: https://matplotlib.org/examples/color/colormaps_reference.html
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm # This allows different color schemes
# Generate an array of increasing values
a=np.arange(0,400)
a = a.reshape(20,20)
# Plot the heatmap using 'inferno' from the cm colour schemes
plt.imshow(a,interpolation='nearest', cmap=cm.inferno)
# Add a scale bar
plt.colorbar()
plt.show()
One thought on “45. Matplotlib: A simple heatmap”