我有一个名为gender的数组,它存储男性和女性的销售数量。我正在尝试创建这些项目的堆叠条形图,但该图显示了y轴上7处的堆叠条形图变为y轴上的下一个堆叠条形图,该堆叠条形图在y轴上上升到14,但应该上升到28。
gender = [[7],[14]]
attributes = ("Male & Female")
y_pos = np.arange(len(attributes))
plt.bar(y_pos, gender[0], align='center', alpha=0.5)
plt.bar(y_pos, gender[1], align='center', alpha=0.5)
plt.xticks(y_pos, attributes)
plt.ylabel('Volume')
plt.xlabel('Customer Attributes')
plt.title('Number of Customer Types')
plt.show()发布于 2019-11-22 18:27:06
我不能完全肯定我是否正确理解了你的问题。但是,如果您希望第二个条形图位于第一个条形图的顶部,可以通过将第二个条形图的bottom参数设置为第一个条形图的高度来实现,如下所示:
gender = [(7),(14)]
attributes = ["Male & Female"]
y_pos = np.arange(len(attributes))
plt.bar(y_pos, gender[0], align='center', alpha=0.5)
plt.bar(y_pos, gender[1], align='center', alpha=0.5, bottom=gender[0])
plt.xticks(y_pos, attributes)
plt.ylabel('Volume')
plt.xlabel('Customer Attributes')
plt.title('Number of Customer Types')
plt.show()

https://stackoverflow.com/questions/58990383
复制相似问题