Python matlibplot中两个向量之间的填充区域

Python matlibplot中两个向量之间的填充区域,python,numpy,matplotlib,rotation,seaborn,Python,Numpy,Matplotlib,Rotation,Seaborn,以下代码计算以下向量: 方向矢量(红色)和两个矢量(蓝色),通过逆时针旋转红色矢量60度来实现 import matplotlib.pyplot as plt import numpy as np def Visualize(orienVector,vector1,vector2): # Create figure and subplot fig = plt.figure() ax = fig.add_subplot(1, 1, 1) # Plot data points #ax

以下代码计算以下向量: 方向矢量(红色)两个矢量(蓝色),通过逆时针旋转红色矢量60度来实现

import matplotlib.pyplot as plt
import numpy as np


def Visualize(orienVector,vector1,vector2):
 # Create figure and subplot
 fig = plt.figure()
 ax = fig.add_subplot(1, 1, 1)

 # Plot data points
 #ax.scatter(vector1[0], vector1[1], color='blue')
 #ax.scatter(vector2[0], vector2[1], color='orange')

 # Set limits for x and y axes
 plt.xlim(-1, 1)
 plt.ylim(-1, 1)

 # ===== Important bits start here =====

 # Set properties of spines
 ax.spines['top'].set_color('none')
 ax.spines['left'].set_position('zero')
 ax.spines['right'].set_color('none')
 ax.spines['bottom'].set_position('zero')

 # Set axis tick positions
 ax.xaxis.set_ticks_position('bottom')
 ax.yaxis.set_ticks_position('left')

 # Set specific tick locations
 ax.set_xticks([-10,-5, 0, 5 , 10])
 ax.set_yticks([-10,-5, 0, 5 , 10])

 # ===== End Of Important Bits =====

 # Draw arrows
 ax.arrow(0, 0 , vector1[0][0], vector1[1][0], 
    head_width=0.03, 
    head_length=0.1, 
    lw=1, 
    fc='blue', 
    ec='blue', 
    length_includes_head=True)
    
 ax.arrow(0, 0 , vector2[0][0], vector2[1][0], 
    head_width=0.03, 
    head_length=0.1, 
    lw=1, 
    fc='blue', 
    ec='blue', 
    length_includes_head=True)

 ax.arrow(0, 0 , orienVector[0][0], orienVector[1][0], 
    head_width=0.03, 
    head_length=0.1, 
    lw=2, 
    fc='red', 
    ec='red', 
    length_includes_head=True)

 plt.show()

# rotation matrix clockwise
def rotMatrixClockWise(angle):
 c, s = np.cos(angle), np.sin(angle)
 R = np.array([[c, -s], [s, c]])
 return R 

# rotation matrix clockwise
def rotMatrixCounterClockWise(angle):
 c, s = np.cos(angle), np.sin(angle)
 R = np.array([[c, s], [-s, c]])
 return R  

# center of the poit of interests POIS
POI_X = [10,12,15,17,20,50]
POI_Y = [20,30,25,22,19,35]

# position of the pedestrian 
pedPostion = np.array([[3],[4]])

# range of the horisontal angel view
spanningAngle = np.radians(60)

# calculate the cone 
for angle in range(0,360,5):
 
    
 # calculating the component of orientation vector V0, where the length |V0| = 1 
 x0 = 5*np.cos(np.radians(angle))
 y0 = 5*np.sin(np.radians(angle)) 
 v0 = np.array([[x0],[y0]])
 
 v1 = rotMatrixCounterClockWise(spanningAngle).dot(v0) 
 v2 = rotMatrixClockWise(spanningAngle).dot(v0) 


 Visualize(v0,v1,v2)
该向量的输出如下所示

我试图填充蓝色向量之间的区域,以获得如下所示的圆锥体:

圆锥体头部(0,0)与圆弧之间的距离始终为5


然而,我不能让它工作。我是Matlibplot的新手

您可以解析地计算出圆弧中的点(圆的一部分,因此y=+-(1-x^2)**0.5),将它们添加到由红色和黄色向量的原点和端点定义的多边形中,然后使用
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill.html


这里有一个填充多边形的示例:

可能不完全符合您的要求,但您可以在向量之间创建一个楔子。拟合椭圆并填充两者之间的坐标更合适。下面是楔块的一个示例

将matplotlib.pyplot导入为plt,numpy导入为np
从matplotlib导入修补程序
v1=np.数组((1,2))
v2=np.数组((1,-2))
base=np.数组((0,0))
θ1=np.rad2deg(np.arctan(v1[1]/v1[0]))
θ2=np.rad2deg(np.arctan(v2[1]/v2[0]))
图,ax=plt.子批次()
a、 b=θ1,θ2
如果b>a:
a、 b=b,a
艺术家=贴片。圆弧(底部,
宽度=1,
高度=1,
θ1=a,
θ2=b,
颜色=‘绿色’)
ax.箭头(*底部,*v1,颜色='黑色')
ax.箭头(*底部,*v2,颜色='黑色')
ax.箭头(*底部,*(v2+v1),颜色='红色')
楔块=补片。楔块(底部,
r=1,
宽度=1,
θ1=θ2,
θ2=θ1,
颜色=‘绿色’)
ax.添加补片(楔块)
图2(图3)

你可以考虑编辑你的问题做一个最小的可重复的例子,谢谢你的回答,你能通过一个例子来表达吗?链接到示例PoestDeld,遗憾的是,在MatMattLIB中没有一个填充选项。注意<代码> Ax.StIIGHOND(“相等”,可调整=‘DATALIM’)将更新绘图,使圆弧不被拉伸。@cvanelteren。谢谢你的回答。但是,由于基向量逆时针旋转,因此无法正确绘制圆弧。如何通过角度更新调整圆弧/change@Zang322您需要重新计算角度,通过更新面片的属性或删除面片并重新绘制面片来重新绘制面片。@cvanelteren。现在它工作了,问题出在arctan()中,因为它的值介于-90和90之间。我用的是arctan2,现在可以用了