让我们使用FancyArrowPatch在两个分散点之间绘制一个箭头:
import matplotlib.pyplot as plt
import matplotlib as mpl
fig, ax = plt.subplots()
points = ax.scatter([0,1],[0,1], marker='o', s=300)
arrow = mpl.patches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>', mutation_scale=20)
ax.add_patch(arrow)
fig.show()
看起来还可以
现在,让我们做同样的图,但使用PatchCollection
import matplotlib.pyplot as plt
import matplotlib as mpl
fig, ax = plt.subplots()
points = ax.scatter([0,1],[0,1], marker='o', s=300)
arrow = mpl.patches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>', mutation_scale=20)
col = mpl.collections.PatchCollection([arrow])
ax.add_collection(col)
fig.show()
有人能解释一下发生了什么吗?
1条答案
按热度按时间cwtwac6a1#
FancyArrowPatch
主要设计用于注解。显然缺乏与其他补丁的兼容性,因此是PatchCollection。(正如@tom在评论中指出的那样,链接到[这个问题])。解决方法是从箭头的路径创建一个新的补丁,并将该新补丁添加到集合中。这不允许保留
FancyArrowPatch
的所有功能,因此最终是否完全不使用PatchCollection不是一个更好的解决方案是值得怀疑的。