如何去除 FancyArrowPatch 的箭头尖端和目标点之间的空白? [英] How to remove the whitespace between the tip of the arrow of a FancyArrowPatch and the target points?
问题描述
在制作将大量焦点集中在某些箭头上的图像时,我注意到箭头没有达到指定点之间的全长.
例如:
将matplotlib.pyplot导入为plt将Matplotlib导入为mpl无花果,ax = plt.subplots()fig.set_size_inches(5,5)w = 0.001小时 = 1000ax.set_xlim(0, w)ax.set_ylim(0, h)ax.add_artist(mpl.patches.FancyArrowPatch((w*1/3, h*0.0),(宽*1/3,高*1.0),边缘颜色='黑色',facecolor='红色',arrowstyle = mpl.patches.ArrowStyle.CurveFilledAB(head_length = 10,head_width = 10)))ax.add_artist(mpl.patches.FancyArrowPatch((w * 2/3,h * 0.0),(w * 2/3,h * 1.0),边缘颜色='黑色',facecolor ='红色',arrowstyle=mpl.patches.ArrowStyle.Simple(head_length=10, head_width=10, tail_width=1)))plt.savefig('main.svg',format ='svg',bbox_inches =紧",dpi=100,)
产生:
这里是浏览器缩放箭头的屏幕截图,显示它们没有触及上面的黑线:
如何在没有空白的情况下让它们完全接触?
在matplotlib == 3.2.2.上进行了测试
相关问题:
-
A是箭头的起点,B是箭头的终点.
的效果linewidth
然而要记住的另一件事是
linewidth
也会影响箭头是否接触到某些东西.例如,如果我在原始代码中添加了夸大的
linewidth = 10
:FancyArrowPatch(收缩A=0,收缩B = 0,线宽=10,
那么结果是:
所以我们注意如何:
- 边缘的轨迹始终是圆形的,因此箭头不再是尖的,而是以较大的线宽变为圆形
-
Simple
和CurveFilledAB
具有不同的绘制算法:Simple
的一种使箭头超出目标,而CurveFilledAB 代码>使其处于运行状态
- 上面的线宽太胖了,以至于隐藏了红色的内部颜色
对于
Simple
(简单)的情况,如果不需要其他边框颜色,则可以使用linewidth = 0
返回带尖的箭头,并控制主箭头tail_width
的箭头线宽.这不适用于
CurveFilledAB
但是:该样式的绘图算法是单独使用边框作为主箭头线,所以我不确定如何单独控制主线宽度不绘制圆角的双箭头,除了绘制两个更难看的简单箭头:When doing an image which puts lots of focus on some arrows, I noticed that the arrows didn't reach the full length between the specified points.
For example:
import matplotlib.pyplot as plt import matplotlib as mpl fig, ax = plt.subplots() fig.set_size_inches(5, 5) w = 0.001 h = 1000 ax.set_xlim(0, w) ax.set_ylim(0, h) ax.add_artist(mpl.patches.FancyArrowPatch( (w*1/3, h*0.0), (w*1/3, h*1.0), edgecolor='black', facecolor='red', arrowstyle=mpl.patches.ArrowStyle.CurveFilledAB(head_length=10, head_width=10) )) ax.add_artist(mpl.patches.FancyArrowPatch( (w*2/3, h*0.0), (w*2/3, h*1.0), edgecolor='black', facecolor='red', arrowstyle=mpl.patches.ArrowStyle.Simple(head_length=10, head_width=10, tail_width=1) )) plt.savefig( 'main.svg', format='svg', bbox_inches='tight', dpi=100, )
produces:
and here is a screenshot of a browser zoom of the arrows showing that they don't touch the black line above:
How to make them touch exactly without that white space?
Tested on matplotlib==3.2.2.
Related questions:
- Alter the width of an annotate arrow in matplotlib
- Matplotlib - set pad between arrow and text in annotate function
解决方案shrinkA=0
andshrinkB=0
This is the first main direct reason why arrows don't touch.
Those values default to
2
, presumably because arrows were originally mostly used in annotations where some space is desired.If I set them to zero:
FancyArrowPatch( shrinkA=0, shrinkB=0,
then the arrows touch as shown at:
A is for the start, and B is for the end of the arrow.
The effect of
linewidth
Another thing to keep in mind however is that the
linewidth
can also affect if the arrow touches something or not.For example, if I add an exaggerated
linewidth=10
to the original code:FancyArrowPatch( shrinkA=0, shrinkB=0, linewidth=10,
then the result is:
so we note how:
- the tracing of the edges is always rounded, and therefore the arrows stop being pointy and become rounded with large line widths
Simple
andCurveFilledAB
have different drawing algorithms: the one forSimple
makes the arrow overrun the target, andCurveFilledAB
makes it under run- the linewidth above was so fat that it hid the red inner color
For the case of
Simple
, if you don't need a different border color, you can get back the pointy arrow withlinewidth=0
, and control the main arrow line width withtail_width
.This does not work for
CurveFilledAB
however: the drawing algorithm for that style is to use the border alone for the main arrow line, so I'm not sure how to separately control the main line width of a double headed arrow without getting the rounded corners, except for drawing two simple arrows which is uglier: matplotlib simple and two head arrows Seems like something that could be patched by adding a newSimpleAB
class.The result of:
FancyArrowPatch( shrinkA=0, shrinkB=0, linewidth=0,
is:
这篇关于如何去除 FancyArrowPatch 的箭头尖端和目标点之间的空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!