【问题标题】:Matplotlib heatmap: Image rotated when heatmap plot over itMatplotlib 热图:当热图在其上绘制时图像旋转
【发布时间】:2015-06-15 16:08:06
【问题描述】:

我正在尝试在图像顶部绘制热图。 我做了什么:

import matplotlib.pyplot as plt
import numpy as np
import numpy.random
import urllib
#downloading an example image
urllib.urlretrieve("http://tekeye.biz/wp-content/uploads/2013/01/small_playing_cards.png", "/tmp/cards.png")
#reading and plotting the image
im = plt.imread('/tmp/cards.png')
implot = plt.imshow(im)
#generating random data for the histogram
x=numpy.random.normal(500, 100, size=1000)
y=numpy.random.normal(100, 50, size=1000)
heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.imshow(heatmap, extent=extent,alpha=.5)
plt.show()

当我将它们绘制在一起时,图像会旋转,上下颠倒,如下所示:

有没有人有办法恢复旧照片?

【问题讨论】:

  • 您的imshow 图像方向可能默认为您的图像所假定的其他方向。尝试 imshow 关键字 origin 并将其设置为 "upper""lower"。注意情节和图像的方向一致——很容易弄错。例如,参见stackoverflow.com/questions/21648379/… 通常图像默认为左上角的原点,而绘图的原点位于左下角。

标签: python matplotlib plot google-visualization heatmap


【解决方案1】:

您需要设置两个imshow 实例的origin。但是,您还需要更改 extent 中的 yedges

implot = plt.imshow(im,origin='upper')
...
extent = [xedges[0], xedges[-1], yedges[-1], yedges[0]]
plt.imshow(heatmap, extent=extent,alpha=.5,origin='upper')

【讨论】:

    猜你喜欢
    • 2020-06-20
    • 2016-01-21
    • 1970-01-01
    • 2020-03-31
    • 2018-11-23
    • 2017-04-23
    • 1970-01-01
    • 2019-09-03
    • 2019-10-17
    相关资源
    最近更新 更多