【发布时间】:2021-05-22 07:11:19
【问题描述】:
我尝试在 matplotlib 中绘制第三个堆叠条,之后是 stackoverflow 上的这篇文章:A third stacked bar in matplotlib
但是我有一个标题中提到的值错误,我不明白为什么我遵循了与帖子中完全相同的过程...
代码如下:
count_faithfull = [2806862, 2798370, 2793310, 2786216, 2780627, 2773589, 2769471, 2764706, 2758180, 2753428, 2745208, 2745208]
count_coward = [15088, 16216, 11432, 11658, 11862, 14706, 12864, 14006, 15327, 12614, 15002, 0]
count_recruit = [0, 6372, 4564, 6273, 7668, 8746, 9241, 8801, 7862, 6782, 6463, 6463]
width = 0.35
year = list(range(202001, 202013)) #We take the last year
p1 = plt.bar(year, count_recruit, width, color='#d62728', )
p2 = plt.bar(year, count_coward, width, bottom=count_recruit)
p3 = plt.bar(year, count_faithfull, width, bottom=count_recruit+count_coward)
plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.gca().ticklabel_format(useOffset=False)
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0], p3[0]), ('Faithfull', 'Coward', "Recruit"))
plt.show()
有人可以帮助我吗?
【问题讨论】:
标签: python matplotlib