2015-10-26 132 views
-1

我试图将二维直方图绘制为热图。将二维直方图保存为python中的热图

下面是代码:

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行的画面,我该如何解决?

enter image description here

回答

3

一个简单的办法是:

pl.pcolor(hist2D) 
pl.colorbar() 
pl.xlim([0,hist2D.shape[1]]) 
pl.ylim([0,hist2D.shape[0]]) 
pl.savefig('graph.png') 

enter image description here

如果你不喜欢这样的解决方案,您可能需要使用imshow代替pcolor

pl.imshow(hist2D, interpolation='none') 
pl.colorbar() 
pl.savefig('graph.png')