matplotlib: log transform counts in hist2d

前端 未结 1 671
太阳男子
太阳男子 2021-02-08 00:13

Is there a simple way to get log transformed counts when plotting a two dimensional histogram in matplotlib? Unlike the pyplot.hist method, the pyplot.hist2d method does not see

1条回答
  •  长发绾君心
    2021-02-08 00:46

    It's kind of embarrassing, but the answer to my question is actually in the docstring of the corresponding code:

    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`.
    

    So this works:

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

    0 讨论(0)
提交回复
热议问题