动画图例-使用Python 3中的matplotlib创建-不';无法在保存的gif中显示
在下面的代码中,我为每一个创建了两个动画情节和一个动画图例。 在代码执行期间,一切都按预期进行。我看到了动画和传奇。 但是,当我打开保存的.gif文件时,我注意到图例丢失了。 为什么?我如何解决这个问题动画图例-使用Python 3中的matplotlib创建-不';无法在保存的gif中显示,python,matplotlib,animation,Python,Matplotlib,Animation,在下面的代码中,我为每一个创建了两个动画情节和一个动画图例。 在代码执行期间,一切都按预期进行。我看到了动画和传奇。 但是,当我打开保存的.gif文件时,我注意到图例丢失了。 为什么?我如何解决这个问题 import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation f = [] fig, ax = plt.subplots(1,2) x = np.arange(0,1,
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
f = []
fig, ax = plt.subplots(1,2)
x = np.arange(0,1,step=0.01)
for p in np.arange(0, 1.1, step=0.1):
y1 = np.sin(p*x)
y2 = np.cos(p*x)
p1, = ax[0].plot(x, y1, 'C0-o', markersize = 4)
l1 = ax[0].legend(['$\chi$ = ' + "{:.2f}".format(p)], loc='upper left')
p2, = ax[1].plot(x, y2, 'C1-o', markersize = 4)
l2 = ax[1].legend(['$\chi$ = ' + "{:.2f}".format(p)], loc='upper left')
plt.tight_layout()
f.append([p1, l1, p2, l2])
ani = animation.ArtistAnimation(fig, f, interval=100, blit=True, repeat_delay=1000)
plt.show()
wrt=animation.PillowWriter(fps=10)
ani.save('./animation.gif', writer=wrt)