如何使 Matplotlib 极坐标图中的角度顺时针旋转,顶部为 0°?

matplotlibserver side programmingprogramming更新于 2025/4/30 16:52:17

要使 Matplotlib 极坐标图中的角度顺时针旋转,顶部为 0°,我们可以采取以下步骤−

步骤

  • 向当前图形 ax 添加子图。
  • 要将极坐标图设置为顺时针旋转,顶部为 0o,请使用 set_theta_direction() 方法将 theta 方向设置为 −1。并且,使用 set_theta_offset() 方法设置 0 点位置的偏移量(以弧度为单位)。
  • 使用 numpy 创建 theta。
  • 在当前轴上绘制 theta 和 sin(theta)。
  • 要显示图形,请使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
ax = plt.subplot(1, 1, 1, projection='polar')
ax.set_theta_direction(-1)
ax.set_theta_offset(np.pi / 2.0)
theta = np.linspace(0, 2 * np.pi, 37)
ax.plot(np.sin(theta), theta)
plt.show()

输出


相关文章