【问题标题】:Animating contourf plot动画轮廓图
【发布时间】:2014-08-28 04:57:09
【问题描述】:

我正在尝试为等高线图制作动画。以下示例与我想要实现的目标足够接近(来自this archive):

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 2 * np.pi, 0.1)
X,Y = np.meshgrid(x,x)
f1 = np.sin(X) + np.sin(Y)
f2 = np.cos(X) + np.cos(Y)

plt.figure()
C = plt.contourf(f1)
plt.show()

for coll in C.collections:
    plt.gca().collections.remove(coll)

C = plt.contourf(f2)
plt.draw()

但是,remove 命令似乎存在问题,我不确定如何解决。

【问题讨论】:

  • 有什么问题?你能指望什么?会发生什么?

标签: python animation matplotlib


【解决方案1】:

你可能想添加

plt.pause(0.1)

remove 命令之后。这使得 matplotlib 实际上将绘图绘制到这一点并等待 0.1 秒,以便您可以看到正在发生的事情,然后再继续下一次迭代。

【讨论】:

    猜你喜欢
    • 2015-07-06
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 2021-01-05
    相关资源
    最近更新 更多