在 Matplotlib 中的极轴上绘制散点图
要在 Matplotlib 中的极轴上绘制散点图,可以按照以下步骤进行:−
- 设置图形大小并调整子图之间和周围的填充。
- 初始化一个变量 N ,用于存储示例数据的数量。
- 使用 numpy 获取 r、theta、area 和 color 数据。
- 创建一个新图或激活现有图。
- 使用 scatter() 方法,绘制 theta、r、colors 和 area 。
- 使用 show() 方法来显示图形。
示例
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta
fig = plt.figure()
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
plt.show()