牧羊人nacy
以下示例创建一个具有 7 个高度值和 8 个边界的条形图。连续边界之间的差值用作条宽度。条形默认与其中心对齐,但在处理宽度不均匀时,align='edge'则需要对齐。from matplotlib import pyplot as pltimport numpy as npbounds = np.array([21000, 31000, 41000, 53000, 62000, 73000, 81000, 90000])heights = np.random.randint(50000, 120000, len(bounds) - 1)plt.bar(bounds[:-1], heights, width=np.diff(bounds), align='edge', color='crimson', ec='navy')# plt.xticks(bounds) # to have the boundaries as x ticksplt.show()