在 python 中将 2D 直方图保存为热图
Save 2D histogram as heatmap in python
我正在尝试将 2D 直方图绘制为热图。
代码如下:
def save_2d_hist(hist2D):
import pylab as pl
print hist2D.shape
pl.pcolor(hist2D)
pl.colorbar()
pl.savefig('graph.png')
我的 hist 是 (11L, 10L) 但是我得到的图片有 12 行,我该如何解决?
一个简单的选择是:
pl.pcolor(hist2D)
pl.colorbar()
pl.xlim([0,hist2D.shape[1]])
pl.ylim([0,hist2D.shape[0]])
pl.savefig('graph.png')
如果您不喜欢该解决方案,您可能希望使用 imshow
而不是 pcolor
pl.imshow(hist2D, interpolation='none')
pl.colorbar()
pl.savefig('graph.png')
我正在尝试将 2D 直方图绘制为热图。
代码如下:
def save_2d_hist(hist2D):
import pylab as pl
print hist2D.shape
pl.pcolor(hist2D)
pl.colorbar()
pl.savefig('graph.png')
我的 hist 是 (11L, 10L) 但是我得到的图片有 12 行,我该如何解决?
一个简单的选择是:
pl.pcolor(hist2D)
pl.colorbar()
pl.xlim([0,hist2D.shape[1]])
pl.ylim([0,hist2D.shape[0]])
pl.savefig('graph.png')
如果您不喜欢该解决方案,您可能希望使用 imshow
而不是 pcolor
pl.imshow(hist2D, interpolation='none')
pl.colorbar()
pl.savefig('graph.png')