我只想要一条纯粹的扇形线,而不是一个楔子。我试着用它来表示矢量方向的不确定性,在矢量箭头的顶端。我使用plt.arrow在matplotlib中绘制底图上的箭头。
除了楔子之外,我找不到任何方法来表达这种不确定性。我想知道是否有可能在箭头的顶端绘制一条扇形线。
发布于 2016-07-19 22:59:47
假设你有一个相对于某个原始v_origin
的任意向量v
,并且它的角度不确定度:
import pylab as plt
import numpy as np
#plt.style.use('ggplot') # because it's just better ;)
v_origin = [.2, .3]
v = [1., 1.]
angular_uncert = 20. # angular uncertainty of vector in degrees
v_angle = np.arctan2( v[1] ,v[0] ) # starting angle
# plot the arrow
fig = plt.figure(1)
ax = plt.gca()
ax.arrow(v_origin[0], v_origin[1] ,v[0], v[1],
head_width=0.05,
head_length=0.1,
lw=2,
fc='#777777',
ec='#777777',
length_includes_head=True)
# plot the sector line
uncert = (angular_uncert/2.) *np.pi / 180.
r = np.linalg.norm( v ) # length of vector
t = np.linspace( v_angle - uncert , v_angle+uncert , 100) # angular range of sector
x = r* np.cos(t) + v_origin[0] # sector x coords
y = r* np.sin(t) + v_origin[1] # sector y coords
ax.plot( x,y, lw=2, ls='--') # plot the sector
ax.plot( v_origin[0], v_origin[1], 'o', ms=10, c='Limegreen' ) # plot the origin
# adjust the figure
ax.set_xlim(0, 1.6)
ax.set_ylim(0, 1.6)
ax.set_aspect('equal')
fig.show()
https://stackoverflow.com/questions/38469404
复制相似问题