图片在 ax.imshow() 中颠倒了,但更改 origin 关键字并不能解决问题

Image is upside down in ax.imshow() but changing the origin keyword doesn't fix the problem

matplotlib 子图中的图像反转。将 'origin' 关键字从 'upper' 更改为 'lower' 没有任何区别。当我单独绘制图像时,它绘制得很好。

我正在尝试在 matplotlib 中可视化散点图和等高线图后面的图像。此可视化是六个不同子图中的一个子图。问题是图像上下颠倒,我尝试将 'origin' 关键字从 'upper' 更改为 'lower' 但奇怪的是,这对我的情况没有任何影响。谁能告诉我为什么会发生这种情况以及如何解决这个问题?以下是我使用的代码的相关部分。该图像是一个 560 X 550 X 3 的 numpy 数组。

问题代码

fig, axes = plt.subplots(nrows=3, ncols=2) 

"plot 1"
Dataframe[scorer][bodyparts2plot[0]].plot.scatter('x', 'y', 
               c = '#a98d19', ax=axes[0,0], xlim = (0,560), ylim = (0,550),
               figsize= (20,20), title = bodyparts2plot[3], alpha = 0.1) 
axes[0,0].imshow(image) # plot image
df = Dataframe[scorer][bodyparts2plot[0]][['x','y']]
sns.kdeplot(df,cmap='jet', n_levels=50,ax=axes[0,0]) # plot contour

"plot 2"
Dataframe[scorer][bodyparts2plot[1]].plot.scatter('x', 'y',
                c = '#006666', ax=axes[0,1], xlim = (0,560), ylim = (0,550),
                figsize= (20,20), title = bodyparts2plot[4], alpha = 0.1) 

axes[0,1].imshow(image) # plot image
df = Dataframe[scorer][bodyparts2plot[1]][['x','y']]
sns.kdeplot(df,cmap='jet', n_levels=50, ax=axes[0,1]) # plot contour

将 axes.imshow() 中的 'origin' 关键字更改为 "upper" 或 "lower" 没有任何区别

这有效,但不是我想要的

当我做

plt.imshow(image)

图像显示正常。

这是目前的情况: image with problem

我想要的是图像是颠倒的。像这样: example 但覆盖了所有其他内容。

您的问题出在您最初的 pandas df.plot.scatter() 调用上,或者您在其中指定 de ylim= 的事实。您强制轴从底部的 0 开始,而 imshow() 在图像顶部绘制 0。

更改为 df.plot.scatter(..., ylim=(550,0), ...) 应该可以解决问题