我试图从一个给定的分布中绘制一个热图。例如,2D数组的正态分布如下所示:


如果我有另一个像这样的密度图:

我怎么能画出一张像第一张的热图。这是我用来绘制第一张热图的代码:
output_width = 40
output_height = 40
p_x = 20
p_y = 20
sigma = 1
X1 = np.linspace(0, output_width, output_width)
Y1 = np.linspace(0, output_height, output_height)
[X, Y] = np.meshgrid(X1, Y1)
X = X - floor(p_x)
Y = Y - floor(p_y)
D2 = X * X + Y * Y
E2 = 2.0 * sigma ** 2
Exponent = D2 / E2
heatmap = np.exp(-Exponent)
heatmap = (heatmap - heatmap.min()) / (heatmap.max() - heatmap.min())
plt.imshow(heatmap)发布于 2022-07-14 10:54:49
output_width = 40
output_height = 40
mu = 0; sigma=0.1
x, y = np.meshgrid(np.linspace(-1, 1, 40),
np.linspace(-1, 1, 40))
dst = np.sqrt(x**2+y**2)
# lower normal part of gaussian
normal = 1/(2.0 * np.pi * sigma**2)
# Calculating Gaussian filter
gauss = np.exp(-((dst-mu)**2 / (2.0 * sigma**2))) * normal
plt.imshow(gauss)给予:

https://stackoverflow.com/questions/72978626
复制相似问题