是否可以将 Python matplotlib.pyplot.hist 中的 X 轴从 bin 边缘切换为精确值?

Is it possible to switch X axis in Python matplotlib.pyplot.hist from bin edges to exact values?

是否可以将 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()