是否可以将 Python matplotlib.pyplot.hist 中的 X 轴从 bin 边缘切换为精确值? 换句话说,这就是我得到的:
dataset = [0,1,1,1,2,2,3,3,4]
plt.hist(dataset, 5, rwidth=0.9)
最佳答案
您可以先计算频率,然后使用条形图
from collections import Counter
import matplotlib.pyplot as plt
dataset = [0,1,1,1,2,2,3,3,4]
freqs = Counter(dataset)
plt.bar(freqs.keys(), freqs.values(), width=0.9)
plt.show()
关于python-3.x - 是否可以将 Python matplotlib.pyplot.hist 中的 X 轴从 bin 边缘切换为精确值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62310216/