py柱状叠加

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()
# -*- coding:utf-8 -*-
import matplotlib.pyplot as plt
import matplotlib as mpl
 
mpl.rcParams["font.sans-serif"] = ["SimHei"]
 
x = [1, 2, 3, 4, 5, 6 ,7,8,9,10,11,12,13,14]
y = [0.4101,0.4535,0.4881,0.4604,0.4539,0.4054,0.4359,0.4531,0.4471,0.4630,0.4542,0.4235,0.4301,0.4523]
y1 = [0.2874,0.2647,0.2335,0.2579,0.2553,0.2837,0.2336,0.2050,0.2243,0.2233,0.2194,0.2341,0.2266,0.1904]
y2 = [0.3023,0.2817,0.2782,0.2816,0.2907,0.3108,0.3304,0.3417,0.3284,0.3135,0.3262,0.3422,0.3432,0.3571]
 
plt.bar(x, y, align="center", color="orange", tick_label=["李世民", "李治", "武曌", "李隆基", "李亨","李豫","李适","李纯","李昂","李炎","李忱","李漼","李儇","李柷"], label="消极")
plt.bar(x, y1, align="center", bottom=y, color="#91B493", label="积极")
for i in range(0, len(y)):
    y1[i] = y1[i] + y[i]
plt.bar(x, y2, align="center", bottom=y1, color="#F6C555", label="中立")
plt.xlabel("xxx")
plt.ylabel("xx")
plt.ylim(0,1)
plt.legend()
plt.show()

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值