import numpy
as np
import matplotlib
.pyplot
as plt
# 绘制饼图
labels
= 'x', 'y', 'z', 'm' # 坐标轴名称
size
= [100, 230, 340, 343]
explode
= (0, 0.1, 0, 0) # 使得y的数据突出
plt
.subplot2grid((3, 3), (0, 0), colspan
=2)
plt
.pie(size
, explode
=explode
, labels
=labels
, autopct
='%1.1f%%', shadow
=False
, startangle
=8) # autopct会显示占比
plt
.axis('equal') # 使得饼图是个正圆
# 绘制直方图
a
= np
.random
.normal(100, 20, size
=100) # 生成均值为
100,方差为
20的
100个数,格式为矩阵
plt
.subplot2grid((3, 3), (1, 2), colspan
=3) # colspan代表分割块的序号
plt
.hist(a
, bins
=20, density
=1, histtype
='stepfilled', facecolor
='b', alpha
=0.5)
# bins
=b20
:从最大到最小生成
20个区间
# density
=1:出现次数变为概率展示
# alpha
=0.5:颜色深度
# 绘制极坐标图
n
= 20 # 划分区间数
theta
= np
.linspace(0.0, 2 * np
.pi
, n
, endpoint
=False
)
radii
= 10 * np
.random
.rand(n
)
width
= np
.pi
/ 4 * np
.random
.rand(n
)
# ax
=plt
.subplot(111,projection
='polar')projection
='polar'绘制极坐标图指令
# 使用plt
.subplot()方法是面向对象的绘制方法,ax是一个对象
ax
= plt
.subplot2grid((3, 3), (1, 0), colspan
=1, projection
='polar')
# 设置极坐标图参数
bars
= ax
.bar(theta
, radii
, width
=width
, bottom
=0.0)
# 颜色设定
for r
, bar
in zip(radii
, bars
):
bar
.set_facecolor(plt
.cm
.viridis(r
/ 10.))
bar
.set_alpha(0.5)
plt
.savefig('C://Users/Administrator/Desktop/test1.png', dpi
=800)
plt
.show()
结果展示
转载请注明原文地址: https://yun.8miu.com/read-136472.html