简体   繁体   中英

How can I plot a heat map contour with x, y coordinates and intensity?

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()

https://i.stack.imgur.com/kzl0b.png

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM