在 Matplotlib 极坐标图上旋转 theta=0

matplotlibserver side programmingprogramming更新于 2025/9/12 1:37:17

要在 matplotlib 极坐标图上设置 theta=0,我们可以采取以下步骤 −

  • 在 0 到 100 的范围内创建随机 theta ;将它们转换为弧度。

  • 使用 set_theta_zero_location() 方法,我们可以将 theta 的位置设置为 0。

  • 使用 plot() 方法绘制 theta_in_rad 和  data_r。

  • 使用 title() 方法设置绘图标题。

  • 要显示图形,请使用  show() 方法。

示例

import numpy as np
import matplotlib.pyplot as plt
import random
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
theta_in_rad = [float(i) * np.pi / 180.0 for i in range(0, 100, 10)]
data_r = random.sample(range(70, 90), 10)
ax = plt.subplot(111, polar=True)
ax.set_theta_zero_location("W")
ax.plot(theta_in_rad, data_r, color='r', linewidth=3)
ax.set_title("Example", va='bottom')
plt.show()

输出


相关文章