重叠的热图无法正确显示

Overleaped heatmap doesn't show correctly

我在图像上方绘制了一个热图(如图像 link 1 所示),带有高斯滤波器和归一化数据。主要问题是 y 轴上没有低于 92 的值,因此绘图不是从 (0,0) 开始,而是从 (0,92) 开始。因此,当我将两张图片(热图和背景图像)放在一起时,图表上有一个突然的切割(如第 2 link 所示,没有背景的热图在哪里)。

那么,如何扩展热图上的轴,使其从 (0,0) 开始?

下面是我目前用来绘制这两个图像的代码。谢谢!

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from scipy.ndimage.filters import gaussian_filter
import matplotlib.colors as mcolors
from sklearn.preprocessing import normalize

x = df['x_data']
y = df['y_data']

heatmap, xedges, yedges = np.histogram2d(x, y, bins = [800,600])

extent = [0, xedges[-1], yedges[0], yedges[-1]]
heatmap = normalize(heatmap)
heatmap = gaussian_filter(heatmap, 16)   

colors = [(1,1-c,0,c) for c in np.linspace(0,1,100)]
cmapred = mcolors.LinearSegmentedColormap.from_list('mycmap', colors, N=5)

map_img = mpimg.imread('dir/to/background/image.png')

fig, ax = plt.subplots(figsize=(16.1, 9.1))

plt.imshow(map_img, extent=[0, 800, 0, 600], cmap = 'Greys_r')
plt.imshow(heatmap.T, extent = extent, origin = 'lower', cmap = cmapred, alpha = 0.7)

plt.ylim([0,600])
plt.xlim([0,800])
plt.show()

Image of heatmap + background: https://imgur.com/2vX6Bw6

Image of only heatmap: https://imgur.com/axMe7K7

您可以手动向热图中添加行。也许更容易尝试明确设置直方图箱?

bins=[np.arange(0, 800, 1), np.arange(0, 600, 1)]
heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)