如何在pyplot中仅使用对数xscale绘制累积直方图

2024-10-01 22:44:08 发布

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

此图绘制对数X刻度和Y刻度。似乎不知道如何仅绘制对数X刻度。

plt.hist(data, bins=10, cumulative=True, log=True)

Tags: logtruedata绘制对数plthistbins
1条回答
网友
1楼 · 发布于 2024-10-01 22:44:08

可以使用以下命令更改y轴上的日志:

plt.gca().set_yscale('linear')

或者在图像对焦时按L键。

但是,使用log=Truehist()不会绘制对数x轴。从docs

matplotlib.pyplot.hist(x, bins=10, ...)

bins: Either an integer number of bins or a sequence giving the bins. If bins is an integer, bins + 1 bin edges will be returned, consistent with numpy.histogram() for numpy version >= 1.3, and with the new = True argument in earlier versions. Unequally spaced bins are supported if bins is a sequence.

因此,如果您只设置bins=10,它们的间距将相等,这就是为什么当您将xscale设置为log时,它们的宽度会减小。要在log xscale中获得等间距的存储箱,您需要如下内容:

plt.hist(x, bins=10**np.linspace(0, 1, 10))

相关问题 更多 >

    热门问题