Issue
Using Matplotlib, I want to plot a 2D heat map. My data is an n-by-n Numpy array, each with a value between 0 and 1. So for the (i, j) element of this array, I want to plot a square at the (i, j) coordinate in my heat map, whose color is proportional to the element's value in the array.
How can I do this?
Solution
The imshow()
function with parameters interpolation='nearest'
and cmap='hot'
should do what you want.
Please review the interpolation
parameter details, and see Interpolations for imshow and Image antialiasing.
import matplotlib.pyplot as plt
import numpy as np
a = np.random.random((16, 16))
plt.imshow(a, cmap='hot', interpolation='nearest')
plt.show()
Answered By - P. Camilleri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.