Matplotlib动画每帧具有不同的标题

时间:2019-04-02 19:27:09

标签: python matplotlib animation

我有一个想要制作动画的2D数组序列。我想自定义一些框架,例如通过添加不同的标题。

N_TIME_STEPS=100
records = get_records()
# records is a 250 X 250 X N_TIME_STEPS ndarray
ims = []
fig = plt.figure()
for i in range(N_TIME_STEPS):
    count_map = records[:, :, i]
    ax = plt.subplot(111)
    ax.set_title(f"step {i}")
    ax.set_ylabel(r'$k$')
    ax.set_xlabel(r'$\tau_{0}$')
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    im = ax.imshow(count_map, cmap="inferno", origin='lower', extent=[0, 1, 0, 1])
    plt.colorbar(im, cax=cax)
    ims.append([im])
ani = animation.ArtistAnimation(fig, ims, interval=100, blit=False, repeat_delay=1000)

这不起作用。所有框架的标题均为“第99步”

Matplotlib有助于提供以下警告

Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance

但是当我尝试这个建议并使用

ax = plt.subplot(111, label=str(i))

我无法解释

Process finished with exit code -1073740791 (0xC0000409)

我在做什么错了?

注意:{bl}的答案this对我没有帮助,因为blit设置为False,并且我希望标题不在情节之外。 this问题的答案也无关紧要

0 个答案:

没有答案