Python 画简单堆叠柱状图 (数据可视化)

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()

结果:

  • 23
    点赞
  • 134
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值