【问题标题】:Adding new patches to a matplotlib plot while an animation is occurring (Python)在动画发生时向 matplotlib 图添加新补丁(Python)
【发布时间】:2015-04-09 10:16:59
【问题描述】:

有谁知道如何在函数调用中为绘图添加补丁?看来我只能在通话之外而不是在通话中添加新补丁。这是我的代码,我知道由于 print 语句正在执行该函数,但没有添加新补丁:

fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(7, 6.25)
ax = plt.axes(xlim=(0, 138), ylim=(0, 79))
ax.add_patch(plt.Rectangle((9, 1), 120, 1))
ax.add_patch(plt.Rectangle((9, 77), 120, 1))

rect = patches.Rectangle((xa3-6, ya4+0.75), 12, 12)
def upRamp(newPatch):
    global ax
    print "Ramp"
    ax.add_patch(newPatch)

upRamp(rect)

感谢您的帮助!

【问题讨论】:

    标签: python matplotlib patch


    【解决方案1】:

    您的代码在我的机器上将补丁添加到 ax 就好了。如果您还没有检查过,您可以通过检查来确定是否添加了补丁:

    print(ax.patches)
    

    在您的代码 sn-p 中,您没有定义 xa3 或 ya4 - 我冒昧地猜测它们可能采用了意味着您的补丁“rect”位于 xlim 和 ylim 定义的绘图区域之外的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2019-02-20
      相关资源
      最近更新 更多