Python全系列 教程
3567个小节阅读:5929.7k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
pie函数可以绘制饼状图,饼图主要是用来呈现比例的。只要传入比
例数据即可。
【示例】绘制饼状图
xxxxxxxxxx
251#导入模块
2import matplotlib.pyplot as plt
3import numpy as np
4#准备男、女的人数及比例
5man=71351
6woman=68187
7man_perc=man/(woman+man)
8woman_perc=woman/(woman+man)
9#添加名称
10labels=['男','女']
11#添加颜色
12colors=['blue','red']
13#绘制饼状图 pie
14plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
15# labels 名称 colors:颜色,explode=分裂 autopct显示百分比
16paches,texts,autotexts=plt.pie([man_perc,woman_perc],labels=labels,colors=colors,explode=(0,0.05),autopct='%0.1f%%')
17
18#设置饼状图中的字体颜色
19for text in autotexts:
20 text.set_color('white')
21
22#设置字体大小
23for text in texts+autotexts:
24 text.set_fontsize(20)
25plt.show()
实时学习反馈
1. 使用matplotlib模块中___函数可以绘制饼图,饼图主要是用来呈现比例的。
A plot
B scatter
C bar
D pie
2. 使用matplotlib模块绘制饼图,下划线处需要填写的代码是___:
xxxxxxxxxx
131#准备男、女的人数及比例
2man=71351
3woman=68187
4man_perc=man/(woman+man)
5woman_perc=woman/(woman+man)
6#添加名称
7labels=['男','女']
8#添加颜色
9colors=['blue','red']
10#绘制饼状图 pie
11plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
12# labels 名称 colors:颜色,explode=分裂 autopct显示百分比
13paches,texts,autotexts=plt.pie(________,labels=labels,colors=colors,explode=(0,0.05),autopct='%0.1f%%')
A [man_perc,woman_perc]
B man_perc,woman_perc
答案
1=>D 2=>A