添加新艺术家时 Matplotlib FuncAnimation 框架不渲染

Matplotlib FuncAnimation frame not rendering when a new artist added

我在 Matplotlib 中制作动画,每隔几帧就会添加新艺术家(特别是补丁),但是当我 运行 它时,添加新艺术家的每一帧都是完全空白的。我知道 blitting 有一些问题,因为当我关闭它时它会起作用,但我需要它。我 return 在每一帧中创建或修改的每个形状,就像文档要求的那样。我正在使用 MacOSX 后端。

我的代码与此类似:

from random import random
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig = plt.figure()
axe = fig.add_axes([0, 0, 1, 1], frameon=False)
circles = []

def update(i):
    if not i % 10:
        new_circle = plt.Circle((random(), random()), 0.05, color='black')
        axe.add_patch(new_circle)
        circles.append(new_circle)

    for circle in circles:
        circle.center = (random(), random())

    return circles

animation = FuncAnimation(fig, update, frames=60, interval=1000/30, repeat=False, blit=True)
plt.show()

这似乎是 MacOSX 后端中 matplotlib 的一个错误,因此解决方案是通过使用不同的后端或尽可能不 blitting 来解决它。