matplotlib极坐标图、极区图、极散点图

列举三个matplotlib中在极坐标下作图的案例:

1. 极坐标图

import numpy as np
import matplotlib.pyplot as plt

# 极坐标下需要的数据有极径和角度
r = np.arange(1,6,1)  # 极径
theta = [i*np.pi/2 for i in range(5)]  #角度

# 指定画图坐标为极坐标,projection='polar'
ax = plt.subplot(111, projection='polar')
ax.plot(theta,r,linewidth=3,color='r')

# 加网格
ax.grid(True)

# 显示图
plt.show()

2. 极区图

plt.axes(polar=True)

# 数据:角度和极径
theta = np.arange(0, 2*np.pi, 2*np.pi/8)  # 角度数据
radii = np.arange(1,9,1)  #极径数据

# 作图, width表示极区所占的区域
plt.bar(theta,radii, width=(2*np.pi/8))

# 与上图一样
ax1 = plt.subplot(111, projection='polar')
ax1.bar(theta, radii, width=(2*np.pi/8))

3. 极散点图

theta = np.arange(0,2*np.pi, np.pi/4)  # 数据角度
r = np.arange(1,9,1)  #数据极径
area = 100*np.arange(1,9,1)  # 数据散点面积
colors = theta

ax2 = plt.subplot(111,projection='polar')
ax2.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha =0.75)

plt.show()

猜你喜欢

转载自blog.csdn.net/huangxiaoyun1900/article/details/82052870