【问题标题】:matplotlib: log transform counts in hist2dmatplotlib:在 hist2d 中记录转换计数
【发布时间】:2014-04-26 09:57:40
【问题描述】:

在 matplotlib 中绘制二维直方图时,是否有一种简单的方法来获取对数转换计数?与pyplot.hist 方法不同,pyplot.hist2d 方法似乎没有日志参数。

目前我正在做以下事情:

import numpy as np
import matplotlib as mpl
import matplotlib.pylab as plt

matrix, *opt = np.histogram2d(x, y)
img = plt.imshow(matrix, norm = mpl.colors.LogNorm(), cmap = mpl.cm.gray, 
                 interpolation="None")

它绘制了预期的直方图,但轴标签显示了 bin 的索引,因此不是预期值。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    有点尴尬,不过我的问题的答案其实在对应代码的docstring中:

    Notes
    -----
        Rendering the histogram with a logarithmic color scale is
        accomplished by passing a :class:`colors.LogNorm` instance to
        the *norm* keyword argument. Likewise, power-law normalization
        (similar in effect to gamma correction) can be accomplished with
        :class:`colors.PowerNorm`.
    

    所以这行得通:

    import matplotlib as mpl
    import matplotlib.pylab as plt
    par = plt.hist2d(x, y, norm=mpl.colors.LogNorm(), cmap=mpl.cm.gray)
    

    【讨论】:

      猜你喜欢
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      相关资源
      最近更新 更多