如何在 matplotlib 中為極座標圖建立次要刻度?


若要在 matplotlib 中為極座標圖建立次要刻度,我們可以採取以下步驟

步驟

  • 設定圖形大小並調整子圖之間和周圍的填充。

  • 使用 numpy 建立r(半徑)和theta資料點。

  • 向當前圖形新增子圖。

  • step=10迭代 0 至 360 之間的所有點,然後繪製它們以獲取刻度

  • 若要顯示圖形,可以使用Show()方法。

示例

import numpy as np
import matplotlib.pyplot as 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()

輸出

它將產生以下輸出 −

更新時間:2021-10-11

1 千次瀏覽

開啟你的職業生涯

完成課程以獲得認證

入門
廣告
© . All rights reserved.