![](/img/trans.png)
[英]How would I hide the control points on a matplotlib Path constructed with CURVE3 or CURVE4
[英]connectionstyle arc3 (FancyArrowPatch) and path CURVE3 - two quadratic Bezier curves, different outcomes?
我從這里提到的類似問題開始: 在matplotlib中用中點箭頭繪制圓形的fancyarrowpatch
只是我想在箭頭上添加標簽,最好在可變的地方。 我試圖用路徑頂點重建坐標,但是標簽仍然到處都是。 然后,我嘗試遵循connection3 arc3的描述
( https://matplotlib.org/api/_as_gen/matplotlib.patches.ConnectionStyle.html?highlight=connectionstyle )
類Arc3(rad = 0.0)
在兩點之間創建簡單的二次貝塞爾曲線。 創建曲線以使中間控制點(C1)距起點(C0)和終點(C2)的距離相同,並且C1到連接C0-C2的線的距離為rad乘以距離C0-C2。
我對此進行了重構,並注意到FancyArrowPatch繪制的曲線與具有指定點的二次Bezier曲線不同。
最小示例:
import numpy
import matplotlib
from matplotlib import pyplot as plt
import matplotlib.path as mpath
import matplotlib.patches as mpatches
from matplotlib.patches import FancyArrowPatch, Circle
fig = plt.figure(frameon=False)
ax = fig.add_subplot(111, frame_on=False)
rad=0.3
shrink=0.3
# Setting up circles as start and end points
size = 0.1
n1 = Circle([0,0], radius=size, alpha=0., fill=False, linewidth=0.1)
n2 = Circle([1,1], radius=size, alpha=0., fill=False, linewidth=0.1)
ax.add_patch(n1)
ax.add_patch(n2)
# Create a fancy arrow between start and end point
e = FancyArrowPatch(n1.center, n2.center,
connectionstyle='arc3,rad=%s' % rad,
arrowstyle='simple',
clip_on=False,
linewidth=2.,
shrinkA=shrink,shrinkB=shrink
)
ax.add_patch(e)
# Start point
vs=numpy.asarray(n1.center)
# End point
ve=numpy.asarray(n2.center)
# Connection vector start->end
vD=ve-vs
# Perpendicular vector to vD
vp=numpy.asarray([vD[1],-vD[0]])
# Control point: same distance from start and end point, and rad*|vD| from the connection line between start and end
vc=vs+0.5*vD+rad*vp
Path=mpath.Path
pp1 = mpatches.PathPatch(
Path([vs, vc, ve],
[Path.MOVETO, Path.CURVE3, Path.CURVE3]), color="red", transform=ax.transData,fc='None')
ax.add_patch(pp1)
# Putting labels on quadratic Bezier curve at various points
# Uses start point, control point and end point from above
for tt in numpy.arange(0,1.1,0.1):
vl=((1-tt)**2)*vs+(2*(1-tt)*tt)*vc+(tt**2)*ve
string = str(tt)
ax.text(vl[0], vl[1], string,
fontsize=10,bbox={'alpha':0.5, 'pad':2},
verticalalignment='center',
horizontalalignment='center')
plt.show()
這使
黑線:FancyArrowPatch(不知道為什么沒有箭頭)
紅線:PathPatch
藍色標簽:(0,0)和(1,1)之間的二次貝塞爾曲線上的點,控制點距起點和終點的距離相同,而rad *(起點和終點的距離)距起點和終點之間的連接線。 (如connectionstyle arc3中所述)。
(不幸的是,我不能只給FancyArrowPatch構造路徑,因為我需要它的收縮/補丁選項。)
所以問題是我如何可靠地在箭頭上放置標簽,以及FancyArrowPatch實際上是如何構建其路徑的。
(我知道我可以返回頂點,但是我對不同的箭頭長度使用相同的代碼(只有起點和終點不同),並且這些路徑看起來彼此非常不同)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.