【问题标题】:Ratio of 2D histograms in matplotlibmatplotlib 中二维直方图的比率
【发布时间】:2015-04-01 07:48:32
【问题描述】:

我有两组数据,我分别使用 matplotlib 的 hist2d() 绘制二维直方图,如http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html。 现在我想知道这两个二维直方图的比率(即频率的比率)。如何在 matplotlib 中实现这一点?

【问题讨论】:

    标签: matplotlib histogram histogram2d


    【解决方案1】:

    Internally hist2d 使用 numpy.histogram2d。因此,您可以使用此函数计算两个直方图,计算比率,然后使用pcolormeshimshow 或类似方法绘制它。

    h1, xedges, yedges = np.histogram2d(x1, y1, bins=bins)
    h2, xedges, yedges = np.histogram2d(x2, y2, bins=bins)
    h = h1 / h2
    pc = ax.pcolorfast(xedges, yedges, h.T)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2011-08-14
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      相关资源
      最近更新 更多