matplotlib:hist2d中的日志转换计数

2024-04-25 20:09:18 发布

您现在位置:Python中文网/ 问答频道 /正文

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

目前我正在做以下工作:

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

它绘制期望的直方图,但轴标签显示的是存储箱的索引,因此不是期望值。


Tags: 方法importnumpy参数matplotlibasnp绘制
1条回答
网友
1楼 · 发布于 2024-04-25 20:09:18

这有点尴尬,但我问题的答案实际上在相应代码的^{}中:

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)

相关问题 更多 >