[英]Shading a segment between two lines on polar axis (matplotlib)
目前,我有一個用線表示日出(藍色),午間(紅色),日落(橙色)和物體(綠色)方向的圖。 我想在日出和日落之間創建一個黃色陰影區域。 我想到了plt.fill
方法,但是當我添加plt.fill_between(theta1, theta2, R1, alpha=0.2)
時,該方法似乎不起作用。 我認為這是因為兩條線不相交。 我當前的極軸圖如下所示:
腳本的相關部分是:
#for object
theta0 = np.deg2rad([190, 190])
print ("theta0= %s" %theta0)
R0 = [0,0.4]
#for sunrise
theta1 = np.deg2rad([105, 105])
print ("theta1= %s" %theta1)
R1 = [0,1]
#for sunset
theta2 = np.deg2rad([254, 254])
print ("theta2= %s" %theta2)
R1 = [0,1]
#for midday
theta3 = np.deg2rad([0.2, 0.2])
print ("theta3= %s" %theta3)
R3 = [0,1]
ax.set_theta_zero_location("S")
ax.set_theta_direction(-1)
ax.plot(theta1,R1, theta2, R1, theta0, R0, lw=5)
#plt.fill_between(theta1, theta2, R1, alpha=0.2) #does not work
plt.savefig('plot.png')
我還考慮過使用正午的方位角,然后使用根據日落和日出之間的角度差計算得出的寬度,然后使用這些寬度生成陰影區域。 我該怎么做呢? 我只想要日出和日落之間的黃色陰影區域,因此我認為從正午的角度生成width
是個好主意。 我想這樣做的一個重復的ax
以形成ax2
,我可以然后潛在地使用它來顯示width
正午的(陰影區)。 但是,加上ax2
,它似乎弄亂了情節。 我還能如何解決呢?
要在極坐標圖上使用fill_between,必須將其稱為
plt.fill_between(angles_to_go_through, minimum_radii, maximum_radii)
因此,例如,在0到90度之間填充
ax.fill_between(
np.linspace(0, pi/2, 100), # Go from 0 to pi/2
0, # Fill from radius 0
1, # To radius 1
)
這將產生類似
就您而言,您將致電
ax.fill_between(
np.linspace(theta1[0], theta2[0], 100), # Need high res or you'll fill a triangle
0,
1,
alpha=0.2,
color='y',
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.