在 Matplotlib 極座標圖上旋轉 theta=0
要在 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()
輸出
廣告