matplotlib.patches.FancyArrow表现不好吗?

时间:2013-07-31 23:47:45

标签: python matplotlib

在尝试绘制箭头时,我在matplotlib中发现了一种罕见的行为。如果你制作如下图:

import matplotlib.pyplot as plt
import matplotlib.patches as patches

arrow = patches.FancyArrow(0.,0.,0.4,0.6)

fig = plt.figure(1)
ax1  = fig.add_subplot(121)
ax2  = fig.add_subplot(122)

ax1.add_line(arrow)
plt.show()

您将在第一个轴上完美地看到箭头。但是当试图在第二轴上添加相同的箭头时:

import matplotlib.pyplot as plt
import matplotlib.patches as patches

arrow = patches.FancyArrow(0.,0.,0.4,0.6)

fig = plt.figure(1)
ax1  = fig.add_subplot(121)
ax2  = fig.add_subplot(122)

ax1.add_line(arrow)
ax2.add_line(arrow)

plt.show()

您将注意到未绘制箭头。

如果我们尝试制作相同的数字,但现在使用箭头对象的不同副本:

import matplotlib.pyplot as plt
import matplotlib.patches as patches

arrow1 = patches.FancyArrow(0.,0.,0.4,0.6)
arrow2 = patches.FancyArrow(0.,0.,0.4,0.6)

fig = plt.figure(1)
ax1  = fig.add_subplot(121)
ax2  = fig.add_subplot(122)

ax1.add_line(arrow1)
ax2.add_line(arrow2)

plt.show()

可以看到两个箭头,每个面板中有一个箭头。因此,似乎不同方法和对象之间存在依赖关系。有人知道这里发生了什么吗?是FancyArrow越野车吗?谢谢。

1 个答案:

答案 0 :(得分:2)

他们表现得很好,你只是错误地使用它们,你不能将同一个艺术家对象添加到多个axes [将来,这将由以下情况强制执行:图书馆]。

当您将一个艺术家添加到轴时,artistaxes的内部部分会混淆。例如get_axes会返回axes Artist所在的{{1}},如果将其添加到多个轴,则跟踪这将会变得棘手(ier)。

这与为什么在数字之间移动轴很难(After creating an array of matplotlib.figure.Figure, how do I draw them as subplots of One figure?How do I include a matplotlib Figure object as subplot?

有关