如何使 Matplotlib 極座標圖中的角度順時針旋轉,頂部為 0°?
若要讓 matplotlib 極座標圖中的角度順時針旋轉,頂部為 0º,我們可以採取以下步驟。
步驟
- 將子圖新增到當前圖形 ax。
- 若要將極座標圖順時針旋轉,頂部為 0º,請使用 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()
輸出
廣告