绘制3元素堆积柱状图

注意问题:
1)matplotlib 不显示中文问题,需要设置字体

										plt.rc('font', family='STSong', size=8)
										plt.rc('axes', unicode_minus=False)

2)第三个元素的 botoom 是前两个元素相加的结果,但这个相加不是直接让 botom = y1 + y2 ,而是
for i in range ( len(y1)) :
botoom [ i ] = y1 [ i ] + y2 [ i ]

即:

              list(map(sum, zip(agree, against))) 

#coding:gbk
import matplotlib.pyplot as plt
import numpy as np

plt.rc('font', family='STSong', size=8)
plt.rc('axes', unicode_minus=False)

x = ['种\n族\n关\n系', '教\n育', '恐\n怖\n活\n动', '能\n源\n政\n策', '外\n交\n事\n务', '环\n境',
'伊\n拉\n克\n局\n势', '税\n收', '医\n疗\n保\n健\n政\n策', '经\n济', '阿\n富\n汗\n局\n势', '联\n邦\n预\n算\n赤\n字', '外\n来\n移\n民']
agree = [52, 49, 48, 47, 44, 43, 41, 41, 40, 38, 36, 31, 29]
against = [38, 40, 45, 42, 48, 51, 53, 54, 57, 59, 57, 64, 62]
no_opioion = [10, 11, 7, 11, 8, 6, 6, 5, 3, 3, 7, 5, 9]
idx = np.arange(len(x))

width = 0.5
plt.bar(idx, agree, width, color = 'blue')
plt.bar(idx, against,width, bottom = agree, color = 'green')

cum =list(map(sum, zip(agree, against))) 
plt.bar(idx, no_opioion, width, bottom = cum, color = 'yellow')

plt.xticks(idx, x)
plt.show()

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值