網站首頁 編程語言 正文
注:本文的所有數據請移步——?參考數據
一、水平堆疊圖
堆疊圖其實就是柱狀圖的一種特殊形式
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=['戰(zhàn)爭','愛情','動畫','動作','驚悚','劇情'] colors=['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot(cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors)
labels=['戰(zhàn)爭','愛情','動畫','動作','驚悚','劇情'] 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()
原文鏈接:https://blog.csdn.net/wxfighting/article/details/123315504
相關推薦
- 2022-11-03 C#事件中關于sender的用法解讀_C#教程
- 2022-07-30 react組件的生命周期
- 2022-06-21 C語言容易被忽視的函數設計原則基礎_C 語言
- 2023-12-20 Git同時配置Gitee和GitHub
- 2022-11-10 C語言枚舉與聯(lián)合體深入詳解_C 語言
- 2022-09-22 SGL:Self-supervised Graph Learning for Recommendat
- 2022-06-22 Git?Bash終端默認路徑的設置查看修改及拓展圖文詳解_其它綜合
- 2022-05-24 Python?3.x踩坑實戰(zhàn)匯總_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支