Python Matplotlib模块 绘图3(极坐标图)

1.绘制极坐标线形图:

1
2
3
4
5
6
matplotlib.pyplot.polar(<theta>,<r>[,**kwargs])
  #参数说明:
    theta:指定θ坐标,单位为弧度;为数组
      #起始位置为正右方,>0表示逆时针旋转,<0表示顺时针旋转
    r:指定r坐标;为数组
    kwargs:指定其他参数(见下表1,即下图1~2)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
>>> import numpy as np
>>> import matplotlib.pyplot as plt
#设置画布大小:
>>> plt.figure(figsize=(8.0,6.0))
<Figure size 800x600 with 0 Axes>
#设置3个数据,theta为点位置的弧度参数,r为点的半径坐标
>>> theta1=np.array([1.25*np.pi,np.pi/2,0])
>>> theta2=np.array([-np.pi/6,-np.pi/2,0,np.pi/2,np.pi])
>>> theta3=np.arange(0,2*np.pi,0.5)
>>> r1=np.array([4,2,3])
>>> r2=np.array([5,2,4,5,3])
>>> r3=np.random.randint(0,5,13)
#绘制第1个极坐标图:标记样式为细菱形,大小为8,点间的连线样式为":"
>>> plt.polar(theta1,r1,marker='d',ms=8,ls=':',label='数据一')
[<matplotlib.lines.Line2D object at 0x0000017790B9CEC8>]
#填充第1个极坐标图,填充颜色为蓝色,透明度0.3
>>> plt.fill(theta1,r1,color='b',alpha=0.3)
[<matplotlib.patches.Polygon object at 0x0000017790BA9E08>]
#绘制第2个极坐标图,将marker/linestyle/color组合起来以str形式传入
>>> plt.polar(theta2,r2,'*-g',ms=10,label='数据二')
[<matplotlib.lines.Line2D object at 0x0000017790B98B88>]
#绘制第3个极坐标图,设置linestyle=none(点与点之间不相连)
>>> plt.polar(theta3,r3, marker='o',ls='none',ms=8,color='r',label='数据三')
[<matplotlib.lines.Line2D object at 0x0000017791D28B48>]
>>> plt.show()

在这里插入图片描述
2.绘制雷达图:
(1)较粗糙的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
先调用plt.polar(),再调用plt.fill()
  #注意plt.polar()绘制的不是闭合的图像

#实例:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
theta1=np.array([1.25*np.pi,np.pi/2,0])
>>> r1=np.array([4,2,3])
>>> plt.polar(theta1,r1,marker='d',ms=8,ls=':',label='数据一')
[<matplotlib.lines.Line2D object at 0x0000018415A23448>]
>>> plt.fill(theta1, r1, color='b', alpha=0.3)
[<matplotlib.patches.Polygon object at 0x00000184159578C8>]
>>> plt.show()#结果见下图

在这里插入图片描述
(2)更准确的方法: