Python matplotlib 饼图
文章目录
- 一、整理数据
- 二、创建饼图
- 三、爆炸效果
- 四、阴影效果
- 五、为饼图加上百分比
- 六、让饼图旋转不同的角度
- 七、为饼图添加边缘线
- 八、为饼图数据分组
一、整理数据
关于cnboo1.xlsx
,我放在我的码云里,需要的朋友自行下载:cnboo1.xlsx
films=['穿过寒冬拥抱你','反贪风暴5:最终章','李茂扮太子','误杀2','以年为单位的恋爱','黑客帝国:矩阵重启','雄狮少年','魔法满屋','汪汪队立大功大电影','爱情神话']
regions=['中国','英国','澳大利亚','美国','美国','中国','英国','澳大利亚','美国','美国']
bos=['61,181','44,303','42,439','22,984','13,979','61,181','44,303','41,439','20,984','19,979']
persons=['31','23','56','17','9','31','23','56','17','9']
prices=['51','43','56','57','49','51','43','56','57','49']
showdate=['2022-12-03','2022-12-05','2022-12-01','2022-12-02','2022-11-05','2022-12-03','2022-12-05','2022-12-01','2022-12-02','2022-11-05']
ftypes=['剧情','动作','喜剧','剧情','剧情','爱情','动作','动画','动画','动画']
points=['8.1','9.0','7.9','6.7','3.8','8.1','9.0','7.9','6.7','3.8']
filmdescript={'ftypes':ftypes,'bos':bos,'prices':prices,'persons':persons,'regions':regions,'showdate':showdate,'points':points
}
import numpy as np
import pandas as pd
cnbo2021top5=pd.DataFrame(filmdescript,index=films)
cnbo2021top5[['prices','persons']]=cnbo2021top5[['prices','persons']].astype(int)
cnbo2021top5['bos']=cnbo2021top5['bos'].str.replace(',','').astype(int)
cnbo2021top5['showdate']=cnbo2021top5['showdate'].astype('datetime64')
cnbo2021top5['points']=cnbo2021top5['points'].apply(lambda x:float(x) if x!='' else 0)
import pandas as pd
cnbodf=pd.read_excel('cnboo1.xlsx')
cnbodfsort=cnbodf.sort_values(by=['BO'],ascending=False)
cnbodfsort.index=cnbodfsort.TYPE
bo=cnbo2021top5.bos.sort_values()
def mkpoints(x,y):return len(str(x))*(y/25)-3cnbodfsort['points']=cnbodfsort.apply(lambda x:mkpoints(x.BO,x.PERSONS),axis=1)
cnbodfsort['type1']=cnbodfsort['TYPE'].apply(lambda x:x.split("/")[0])
cnbodfgb=cnbodfsort.groupby(["type1"])["ID","BO","PRICE","PERSONS","points"].mean()
cnbodfgbsort=cnbodfgb.sort_values("BO",ascending=False)
二、创建饼图
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.pie(cnbodfgbsort.BO,labels=cnbodfgbsort.index)
plt.show()
这里涉及到简历的漫画效果:详情请访问:为图表添加漫画效果
三、爆炸效果
# 爆炸效果 饼图脱离from matplotlib import pyplot as plt
explo=[0.3,0,0,0,0,0] # 控制爆炸效果,通过更改参数控制距离的长短
plt.style.use('seaborn')
plt.figure(figsize=(15,9))
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP9")
plt.pie(cnbodfgbsort.BO,labels=cnbodfgbsort.index,explode=explo)
plt.show()
四、阴影效果
# 添加阴影效果
# 爆炸效果 饼图脱离from matplotlib import pyplot as plt
explo=[0.3,0,0,0,0,0] # 控制爆炸效果
plt.style.use('seaborn')
plt.figure(figsize=(15,9))
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP9")
plt.pie(cnbodfgbsort.BO,labels=cnbodfgbsort.index,explode=explo,shadow=True)
plt.show()
五、为饼图加上百分比
# 添加阴影效果
# 爆炸效果 饼图脱离from matplotlib import pyplot as plt
explo=[0.3,0,0,0,0,0] # 控制爆炸效果
plt.style.use('seaborn')
plt.figure(figsize=(15,9))
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP9")
plt.pie(cnbodfgbsort.BO,labels=cnbodfgbsort.index,explode=explo,shadow=True,startangle=0,autopct='%1.2f%%')
plt.show()
六、让饼图旋转不同的角度
# 饼图旋转
from matplotlib import pyplot as plt
explo=[0.3,0,0,0,0,0] # 控制爆炸效果
plt.style.use('seaborn')
plt.figure(figsize=(15,9))
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP9")
plt.pie(cnbodfgbsort.BO,labels=cnbodfgbsort.index,explode=explo,shadow=True,startangle=45,autopct='%1.2f%%')
plt.show()
七、为饼图添加边缘线
# 为饼图添加边缘线
from matplotlib import pyplot as plt
explo=[0.3,0,0,0,0,0] # 控制爆炸效果
plt.style.use('seaborn')
plt.figure(figsize=(15,9))
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP9")
plt.pie(cnbodfgbsort.BO,labels=cnbodfgbsort.index,explode=explo,shadow=True,startangle=45,autopct='%1.2f%%',wedgeprops={"edgecolor":"black"})
plt.show()
但是我自己感觉并不是非常明显
八、为饼图数据分组
# 将数据按照票房分类
labels=['>20000','15000-20000','10000-15000','<10000']
c1=cnbodfsort.loc[cnbodfsort.BO>=20000].count()[0]
c2=cnbodfsort.loc[(cnbodfsort.BO>=15000) & (cnbodfsort.BO<20000)].count()[0]
c3=cnbodfsort.loc[(cnbodfsort.BO<15000) & (cnbodfsort.BO>=10000)].count()[0]
c4=cnbodfsort.loc[cnbodfsort.BO<10000].count()[0]
cnbohints=[c1,c2,c3,c4]
from matplotlib import pyplot as plt
explo=[0.3,0,0,0] # 控制爆炸效果
plt.style.use('seaborn')
plt.figure(figsize=(15,9))
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP9")
plt.pie(cnbohints,labels=labels,explode=explo,shadow=True,startangle=45,autopct='%1.2f%%',wedgeprops={"edgecolor":"black"})
plt.show()
Python matplotlib 饼图相关推荐
- python——Matplotlib饼图、直方图的绘制
实验环境 python 3.6 matplotlib 2.2.3 饼图的绘制 matplotlib.pyplot.pie(x, explode=None, labels=None, colors=No ...
- python matplotlib 饼图标签重叠_Python绘制饼图调节字体大小、防止标签重叠解决方法...
设置字体的大小 patches,l_text,p_text=plt.pie(money_rate,explode=explode,labels=names,autopct='%.2f%%') # l_ ...
- Python matplotlib绘制饼图
Python matplotlib绘制饼图 继前面使用matplotlib绘制折线图.散点图.柱状图和直方图,本篇文章继续介绍使用matplotlib绘制饼图. 一.matplotlib绘制饼图 # ...
- python—matplotlib 散点图,气泡图,气泡饼图/功效矩阵可视化对比
python-matplotlib 散点图,气泡图,气泡饼图/功效矩阵可视化对比 刚入行,一直在看大神们的发帖学习,想着自己也写点什么东西,找了好久没找到气泡饼图相关的内容(可能是我眼神不好),于是打 ...
- 不愧是摸鱼高手Python matplotlib 绘制频谱图都会,能怪老板不管
复习回顾 matplotlib 是Python专门用来绘制渲染的模块,其底层主要分为脚本层.美工层和后端.脚本层为我们提供常见图形绘制如折线.柱状.直方.饼图.以往文章 这么详细的Python mat ...
- Python matplotlib 绘制等高线图
前言 我们在往期对matplotlib.pyplot()方法学习,到现在我们已经会绘制折线图.柱状图.散点等常规的图表啦(往期的内容如下,大家可以方便查看往期内容) python入门到进阶,爬虫数据分 ...
- 这么详细的Python matplotlib底层原理浅析
复习回顾 前期,我们已经学习matplotlib模块相关的基础知识,对 matplotlib 模块折线图.饼图.柱状图进行操作. 这么详细的Python matplotlib 绘制图形 还不赶紧收藏 ...
- 这么详细的Python matplotlib 绘制图形 还不赶紧收藏
前言 我们前面对matplotlib模块底层结构学习,对其pyplot类(脚本层)类提供的绘制折线图.柱状图.饼图.直方图等统计图表的相关方法,列举往期文章如下. 超详细的Python matplot ...
- 超详细的Python matplotlib 绘制柱状图
复习回顾 Python 为数据展示提供了大量优秀的功能包,其中 matplotlib 模块可以方便绘制制作折线图.柱状图.散点图等高质量的数据包. 关于 matplotlib 模块,我们前期已经对ma ...
最新文章
- Android 光线传感器的调用
- Linux 技巧: Bash 测试和比较函数
- 竞赛图 计算机网络 应用题,我校学子获2020年“中国高校计算机大赛-网络技术挑战赛”全国总决赛一等奖(图)...
- Google SVN托管和使用学习笔记
- Java Duration类| 带示例的compareTo()方法
- Spring Boot EasyUI edatagrid 扩展
- 一些简单的例子让你在Java中能更好的学习并理解循环结构(1)!
- [Swift]LeetCode921.使括号有效的最少添加 | Minimum Add to Make Parentheses Valid
- Instruments工具的使用
- SQL Server中数据库文件的存放方式,文件和文件组
- 学习自动驾驶技术 学习之路_一天学习驾驶
- java——15位身份证号码升级到18位
- 计算机操作系统复习题
- Android 补间动画之平移动画TranslateAnimation
- 淘宝标品运营技巧,标品如何实现小单量爆搜索
- 五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程
- Fantastic Four: 具有恶意安全的诚实大多数四方安全计算
- 多传感器数据融合发展综述
- MySQL中Count和Sum的区别
- vbnet如何注释_克里斯出售股票为VBNET Develo提供XML注释和文档生成
热门文章
- 同步110序列检测电路
- Django基于admin的stark组件创建(一)
- mysql实现俩个属性加减运算_mysql加减乘除
- 为什么中国公司要让员工用英文名或者花名?
- php怎么安装ecshop,ECSHOP4.0安装教程【ECSHOP4.0安装流程方法】ECSHOP4.0安装步骤-ECSHOP教程网...
- 即将公布的2020年10m分辨率全球土地利用数据(欧空局出品)
- 梦幻西游服务器维修,《梦幻西游》电脑版2017年12月12日定期维护公告
- linux关闭虚拟网卡,KVM---关闭虚拟网卡virbr0的方法
- Mac的最新版本JDK下载失败的解决方法
- Java通过freemaker实现健康报告生成(包含列表、列表合并列)