这是我最后使用的;这是一个小技巧,只需在一个Arc的结尾画出笔直的arrow头:import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Arc
def circarrow(self,diameter,centX,centY,startangle,angle,**kwargs):
startarrow=kwargs.pop("startarrow",False)
endarrow=kwargs.pop("endarrow",False)
arc = Arc([centX,centY],diameter,diameter,angle=startangle,
theta1=np.rad2deg(kwargs.get("head_length",1.5*3*.001)) if startarrow else 0,theta2=angle-(np.rad2deg(kwargs.get("head_length",1.5*3*.001)) if endarrow else 0),linestyle="-",color=kwargs.get("color","black"))
self.axes().add_patch(arc)
if startarrow:
startX=diameter/2*np.cos(np.radians(startangle))
startY=diameter/2*np.sin(np.radians(startangle))
startDX=+.000001*diameter/2*np.sin(np.radians(startangle)+kwargs.get("head_length",1.5*3*.001))
startDY=-.000001*diameter/2*np.cos(np.radians(startangle)+kwargs.get("head_length",1.5*3*.001))
self.arrow(startX-startDX,startY-startDY,startDX,startDY,**kwargs)
if endarrow:
endX=diameter/2*np.cos(np.radians(startangle+angle))
endY=diameter/2*np.sin(np.radians(startangle+angle))
endDX=-.000001*diameter/2*np.sin(np.radians(startangle+angle)-kwargs.get("head_length",1.5*3*.001))
endDY=+.000001*diameter/2*np.cos(np.radians(startangle+angle)-kwargs.get("head_length",1.5*3*.001))
self.arrow(endX-endDX,endY-endDY,endDX,endDY,**kwargs)
import types
plt.circarrow = types.MethodType(circarrow,plt)
函数名为circarrow,作为参数,传递直径、圆心的两个坐标、弧开始的角度和弧应该传递的总角度,以及传递给pyplotarrow的任何参数。若要在弧的开头绘制箭头,请指定startarrow=True,而endarrow=True将在弧的结尾启用箭头。
下面是一个示例图像,您还可以看到箭头样式与直箭头一致:plt.plot(0,0,"o",markersize=10,color="black",mfc="none")
plt.circarrow(.85,0,0,0.05*120,.9*120,startarrow=True,width=0,head_width=.03,head_length=.045,length_includes_head=True,color="black")
plt.circarrow(.85,0,0,1.05*120,.9*120,startarrow=True,endarrow=True,width=0,head_width=.03,head_length=.045,length_includes_head=True,color="black")
plt.arrow(-.2,-.33,.6,+.33,width=0,head_width=.03,head_length=.045,length_includes_head=True,color="black")
plt.axes().set_xlim(-.5,.5)
plt.axes().set_ylim(-.5,.5)
plt.axes().set_aspect(1)
plt.show()