Python 在matplotlib动画中更新三色图

Python 在matplotlib动画中更新三色图,python,animation,matplotlib,Python,Animation,Matplotlib,我一直在尝试从图形tripcolor在matplotlib中创建动画。假设我有 field = ax.tripcolor(tri, C) 如何在每次动画迭代后更改C的值 非常感谢,字段保证是matplotlib.collections.Collection基类的一个实例,该基类为此类情况定义了一个set\u array()方法 在动画的每次迭代中,只需将C的新值传递给字段。set_array()方法。假设您使用FuncAnimation类进行动画,这可能会减少到: fig = plt.figu

我一直在尝试从图形
tripcolor
matplotlib
中创建动画。假设我有

field = ax.tripcolor(tri, C)
如何在每次动画迭代后更改C的值


非常感谢,

字段
保证是
matplotlib.collections.Collection
基类的一个实例,该基类为此类情况定义了一个
set\u array()
方法

在动画的每次迭代中,只需将
C
的新值传递给
字段。set_array()
方法。假设您使用
FuncAnimation
类进行动画,这可能会减少到:

fig = plt.figure()
ax = plt.subplot(111)

field = ax.tripcolor(tri, C)

def update_tripcolor(frame_number):
    # Do something here to update "C"!
    C **= frame_number   # ...just not this.

    # Update the face colors of the previously plotted triangle mesh.
    field.set_array(C)

# To triangular infinity and beyond! (Wherever that is. It's probably scary.)
FuncAnimation(fig, update_tripcolor, frames=10)
另一方面,更新tri要困难得多。虽然这个问题并不试图这样做,但敏锐的读者可能会好奇地了解到,您基本上必须删除、重新创建并将整个三角形网格(即,
字段
)重新添加到此图形的轴上。当然,这既低效又痛苦。(欢迎来到Matplotlib。人口:你。

希望
字段.set_array()
与您同在