如何使用 Matplotlib 以極座標繪圖散點圖?
若要使用 Matplotlib 以極座標繪圖散點圖,我們可以採取以下步驟:
設定影像尺寸並調整子圖之間和周圍的填充。
使用 numpy 建立radii、thetas、theta 和**r** 資料點。
建立一個新影像或啟用現有影像。
將“ax” 作為子圖排列的一部分新增到影像中。
製作多邊形集合以示箭頭。
使用**show()** 方法顯示影像。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True radii = np.linspace(0, 1, 5) thetas = np.linspace(0, 2 * np.pi, 20) theta, r = np.meshgrid(thetas, radii) f = plt.figure() ax = f.add_subplot(polar=True) ax.quiver(theta, r, np.cos(theta) - np.sin(theta), np.sin(theta) + np.cos(theta)) plt.show()
輸出
廣告