python - Matplotlib heatmap: Image rotated when heatmap plot over it -
i trying plot heatmap on top of image. did:
import matplotlib.pyplot plt import numpy np import numpy.random import urllib #downloading example image urllib.urlretrieve("http://tekeye.biz/wp-content/uploads/2013/01/small_playing_cards.png", "/tmp/cards.png") #reading , plotting image im = plt.imread('/tmp/cards.png') implot = plt.imshow(im) #generating random data 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() when plot them together, image get's rotated, up-side down in:

does have solution having old picture back?
you need set origin of both imshow instances. but, need change yedges around in extent
implot = plt.imshow(im,origin='upper') ... extent = [xedges[0], xedges[-1], yedges[-1], yedges[0]] plt.imshow(heatmap, extent=extent,alpha=.5,origin='upper') 
Comments
Post a Comment