修改:最好使用 @tacaswell 的方法。但我的标签将不需要复杂操作即可正确排列,而且柱形图会被分隔开。
希望你的数据在 pandas 中。我将创建一些虚假数据,然后给你一个解决方案。
import pandas as pd
# create a dataframe of number of homes sold
df = pd.DataFrame(data={'sold':np.random.randint(0,100, 1000)})
# groupby the left side of interval [0, 10), [10, 20) etc.. and plot
df.groupby(df.sold // 10 * 10).sum().plot.bar()