Matplotlib条形图宽度仅改变最后一个条形的宽度

2 投票
1 回答
1060 浏览
提问于 2025-04-17 21:19

我有一个柱状图,调整宽度的数值只改变了最后一个柱子的宽度。我附上了图片和代码。有人知道这是为什么吗?

indexes = np.arange(len(labels))
width = 2
pdb.set_trace()
plt.bar(indexes, values, width=2, color="blueviolet")
plt.xlabel("Phenotype identifier", fontdict=font)

enter image description here

1 个回答

3

因为你的柱状图之间重叠了,而且你的数据是单调递增的。比如说,如果你用 indexes=range(10)

plt.bar(indexes, range(10)[::-1], width=2, color="blueviolet")  #indexes should be indices

你会看到:

enter image description here

撰写回答