I'm trying to animate two matplotlib figures at the same time. I wrote a script that creates two instances of matplotlib.animation.FuncAnimation, but only one of them animates, the other remains static.
Here's a minimum working example:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
x=np.linspace(-np.pi,np.pi,100)
# Function for making figures
def makeFigure():
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
# Plot a line
line,=ax.plot(x,np.sin(x))
return fig,ax,line
# Frame rendering function
def renderFrame(i,line):
# Apply a phase shift to the line
line.set_data(x,np.sin(x-i*2*np.pi/100))
return line,
# Make the figures
figcomps1=makeFigure()
figcomps2=makeFigure()
# Animate the figures
for figcomps in [figcomps1,figcomps2]:
fig,ax,line=figcomps
anim=animation.FuncAnimation(fig,renderFrame,fargs=[line])
plt.show()
Is FuncAnimation capable of animating two figures simultaneously? If not, is there another way to simultaneously animate two matplotlib figures?