如何用matplotlib绘制水平和波浪形堆叠图
Admin 2022-09-07 群英技术资讯 550 次浏览
堆叠图其实就是柱状图的一种特殊形式
from matplotlib import pyplot as plt plt.style.use('seaborn') plt.figure(figsize=(15,9)) plt.rcParams.update({'font.family': "Microsoft YaHei"}) plt.title("中国票房2021TOP9") plt.bar(cnbodfgbsort.index,cnbodfgbsort.PERSONS) plt.bar(cnbodfgbsort.index,cnbodfgbsort.PRICE) plt.bar(cnbodfgbsort.index,cnbodfgbsort.points) plt.show()
堆叠图效果
可以看到有部分蓝色的数据被遮挡了,如果我们想全部展现,可以:
index_x=np.arange(len(cnbodfgbsort.index)) index_x w=0.15
from matplotlib import pyplot as plt plt.style.use('classic') plt.figure(figsize=(15,9)) plt.rcParams.update({'font.family': "Microsoft YaHei"}) plt.title("中国票房2021TOP9") plt.bar(index_x,cnbodfgbsort.PERSONS,width=w) plt.bar(index_x+w,cnbodfgbsort.PRICE,width=w) plt.bar(index_x+2*w,cnbodfgbsort.points,width=w) plt.show()
可以看到Excel的数据源当中BO与PRICE和PERSONS的数字相差过大,如果做堆叠图的话,BO会将其他的都进行覆盖,无法显示好的效果:
因为数据相差实在太大,我们可以直接让BO除以1000:
from matplotlib import pyplot as plt plt.style.use('classic') plt.figure(figsize=(15,9)) plt.rcParams.update({'font.family': "Microsoft YaHei"}) plt.title("中国票房2021TOP9") plt.bar(cnbodfgbsort.index,cnbodfgbsort.PERSONS) plt.bar(cnbodfgbsort.index,cnbodfgbsort.PRICE) plt.bar(cnbodfgbsort.index,cnbodfgbsort.BO/1000) plt.bar(cnbodfgbsort.index,cnbodfgbsort.points) plt.show()
from matplotlib import pyplot as plt plt.style.use('classic') plt.figure(figsize=(15,9)) plt.rcParams.update({'font.family': "Microsoft YaHei"}) plt.title("中国票房2021TOP9") plt.bar(index_x-w,cnbodfgbsort.BO/1000,width=w) # 直接让BO除以1000 plt.bar(index_x,cnbodfgbsort.PERSONS,width=w) plt.bar(index_x+w,cnbodfgbsort.PRICE,width=w) plt.bar(index_x+2*w,cnbodfgbsort.points,width=w) plt.show()
labels=['战争','爱情','动画','动作','惊悚','剧情'] colors=['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot(cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors)
labels=['战争','爱情','动画','动作','惊悚','剧情'] colors=['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot(cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.BO/900,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors)
plt.legend()
labels=['票房','票价','人次','评分'] colors=['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot(cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.BO/900,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors) plt.legend()
!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要为大家介绍了Python密码学仿射及攻击单字母密码教程,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
大家好,本篇文章主要讲的是关于Python中的元组介绍,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下,方便下次浏览
基于PyTorch的模型,想固定主分支参数,只训练子分支,结果发现在不同epoch相同的测试数据经过主分支输出的结果不同。
这篇文章主要介绍了Python常用标准库,主要包括pickle序列化和JSON序列化模块,通过使用场景分析给大家介绍的非常详细,需要的朋友可以参考下
利用python可以实现微信消息的一键已读功能,怎么实现呢?你肯定会想着很复杂,但是python的好处就是很多人已经把接口打包做好了,只需要调用即可,今天通过本文给大家分享使用 Python 实现微信消息的一键已读的思路代码,一起看看吧
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008