如何在 Python 直方图中设置对数箱?
pythonmatplotlibserver side programmingprogramming更新于 2024/9/22 5:32:17
我们可以在绘制直方图时使用 plt.hist(bin="") 设置对数箱。
步骤
创建一个数组 x,范围为 100。
使用 plt.hist() 方法绘制直方图。我们可以使用对数箱传递对数箱,该对数箱返回对数刻度上均匀分布的数字。
获取当前轴,如有必要创建一个并设置 X 轴刻度。
要显示图形,请使用 plt.show() 方法。
示例
from matplotlib import pyplot as plt
import numpy as np
x = np.array(range(100))
plt.hist(x, bins=np.logspace(start=np.log10(10), stop=np.log10(15), num=10))
plt.gca().set_xscale("log")
plt.show()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

