目前,我有一个用线条指示日出(蓝色)、中午(红色)、日落(橙色)和物体(绿色)方向的图。我想在日出和日落之间创建一个黄色阴影区域。我想到了这个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')
Run Code Online (Sandbox Code Playgroud)
我还想过使用中午的方位角,然后使用宽度,根据日落和日出之间的角度差计算,然后使用这些来生成阴影区域。我该怎么做呢?我只想要日出和日落之间的黄色阴影区域,因此我认为width从中午的 theta生成是一个好主意。我尝试做一个axto form的副本,ax2然后我可以用它来显示width中午的(阴影区域)。但是加上ax2,好像把剧情搞乱了。我还能如何解决这个问题?
要在极坐标图上使用 fill_between,您必须将其称为
plt.fill_between(angles_to_go_through, minimum_radii, maximum_radii)
Run Code Online (Sandbox Code Playgroud)
因此,例如,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
)
Run Code Online (Sandbox Code Playgroud)
这会产生一个像
在你的情况下,你会打电话
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',
)
Run Code Online (Sandbox Code Playgroud)