I am trying to plot a heat map contour graph like the following: https://i.stack.imgur.com/XrCOe.png
It uses a 6x5 grid for the x and y coordinates. I then have probability values to plot at each of the 30 points. How can I do this?
edit:
import matplotlib.pyplot as plt
import numpy as np
grid = np.zeros((5,5))
grid[0,0]=0.9189
grid[1,0]=0.0767
grid[2,0]=0.01459
grid[3,0]=0.1157
grid[4,0]=0.207
heatmap = plt.imshow(grid, cmap='jet', interpolation='lanczos')
plt.grid(which='major', axis='both', linestyle='-', color='k', linewidth=1)
x=[1,2,3,4,5]
y=[1,2,3,4,5]
plt.xticks(range(0,5),x)
plt.yticks(range(0,5),y)
plt.colorbar(heatmap)
plt.show()
Tell Matplotlib to interpret your grid as an image with interpolation other than the default nearest
:
import matplotlib.pyplot as plt
import numpy as np
grid = np.random.uniform(0, 1, (5, 6))
heatmap = plt.imshow(grid, cmap='jet', interpolation='lanczos')
plt.grid(which='major', axis='both', linestyle='-', color='k', linewidth=1)
plt.colorbar(heatmap)
plt.show()
The output is eg
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.