如何在 matplotlib 中为极坐标图创建次要刻度?

要在 matplotlib 中为极坐标图创建次要刻度,我们可以采取以下步骤

脚步

  • 设置图形大小并调整子图之间和周围的填充。

  • 使用 numpy创建r(半径)和theta数据点。

  • 向当前图窗添加子图。

  • 使用step=10迭代 0 到 360 之间的点并绘制它们以获得刻度

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

示例

import numpy as np
importmatplotlib.pyplotas plt

# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

# radius and theta for the polar plot
r = np.arange(0, 5, 0.1)
theta = 2 *np.pi* r

# Add a subplot
ax = plt.subplot(111, projection='polar')

tick = [ax.get_rmax(), ax.get_rmax() * 0.97]

# Iterate the points between 0 to 360 with step=10
for t in np.deg2rad(np.arange(0, 360, 10)):
    ax.plot([t, t], tick, lw=1, color="red")

# Display the plot
plt.show()
输出结果

它将产生以下输出 -

猜你喜欢