我想用相同的注释注释2个点,并且我希望有2个箭头从该1个注释指向点.
我有以下代码:
import matplotlib.pyplot as plt
plt.plot( [1,2], [1,2], 'o' )
plt.xlim( [0,3] )
plt.ylim( [0,3] )
plt.annotate( 'Yet another annotation', xy=(1,1),
xytext=(1.5, .5),
arrowprops=dict( arrowstyle="->" )
)
plt.annotate( 'Yet another annotation', xy=(2,2),
xytext=(1.5, .5),
arrowprops=dict( arrowstyle="->" )
)
plt.show()
Run Code Online (Sandbox Code Playgroud)
正如您在结果图中所看到的,它可以工作(尽管它可能不是最优雅的方式,因为我在完全相同的位置有两个注释).
然而,我对此不满意:我想让箭头从完全相同的位置开始,目前它们似乎从注释的中心开始,我宁愿让它们从注释边缘的某个地方开始以便他们的起点连接起来.
我如何实现这一目标?
您可以注释箭头的起点.即,让两个箭头从相同的位置开始,没有注释文本,并使用没有箭头的第三个注释来用文本注释这个起始点.
import matplotlib.pyplot as plt
plt.plot( [1,2], [1,2], 'o' )
plt.xlim( [0,3] )
plt.ylim( [0,3] )
plt.annotate( "", xy=(1,1), xytext=(1.3, 2.5),
arrowprops=dict( arrowstyle="->" ) )
plt.annotate( '', xy=(2,2), xytext=(1.3, 2.5),
arrowprops=dict( arrowstyle="->" ) )
plt.annotate( 'Some annotation', xy=(1.3, 2.5),
xytext=(1.3, 2.5) , va = "bottom", ha="center" )
plt.annotate( "", xy=(1,1), xytext=(1.5, .5),
arrowprops=dict( arrowstyle="->",shrinkA=0 ) )
plt.annotate( '', xy=(2,2), xytext=(1.5, .5),
arrowprops=dict( arrowstyle="->",shrinkA=0 ) )
plt.annotate( 'Yet another annotation', xy=(1.5, .5),
xytext=(1.5, .5) , va = "top", ha="left" )
plt.show()
Run Code Online (Sandbox Code Playgroud)
您可以使用该arrowprops
键shrinkA
调整箭头的收缩率,将其设置为零,让两个箭头连接.
归档时间: |
|
查看次数: |
2085 次 |
最近记录: |