概述
import numpy as np
import matplotlib.pyplot as plt
N = 13
S = (52, 49, 48, 47, 44, 43, 41, 41, 40, 38, 36, 31, 29)
C = (38, 40, 45, 42, 48, 51, 53, 54, 57, 59, 57, 64, 62)
d=[]
for i in range(0,len(S)):
sum = S[i] + C[i]
d.append(sum)
M = (10, 11, 7, 11, 8, 6, 6, 5, 3, 3, 7, 5, 9)
#menStd = (2, 3, 4, 1, 2)
#womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N)
# the x locations for the groups
width = 0.35
# the width of the bars: can also be len(x) sequence
p1 = plt.bar(ind, S, width, color='#d62728')#, yerr=menStd)
p2 = plt.bar(ind, C, width, bottom=S)#, yerr=womenStd)
p3 = plt.bar(ind, M, width, bottom=d)
plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5','G6', 'G7', 'G8', 'G9', 'G10', 'G11', 'G12', 'G13'))
plt.yticks(np.arange(0, 81, 20))
plt.legend((p1[0], p2[0], p3[0]), ('S', 'C', 'M'))
plt.show()
结果:
最后
以上就是干净鸡为你收集整理的Python 画简单堆叠柱状图 (数据可视化)的全部内容,希望文章能够帮你解决Python 画简单堆叠柱状图 (数据可视化)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复