【发布时间】: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