【问题标题】:Save 2D histogram as heatmap in python [duplicate]在python中将二维直方图保存为热图[重复]
【发布时间】:2016-01-25 23:28:19
【问题描述】:

我正在尝试将二维直方图绘制为热图。

代码如下:

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

【问题讨论】:

    标签: python image matplotlib histogram heatmap


    【解决方案1】:

    一个简单的选择是:

    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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多