I have a figure with two subplots in it and I want to do animation on both the subplots at different intervals and different functionality. Is it possible to make two FuncAnimation calls? I copied an example program and modified it like below. Only the first animation was working. Is there any way to get this working? Will Artist Animation help here? If any one has insight on this please share your thoughts.
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 23 19:58:24 2021
@author: DELL
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def data_gen(t=0):
cnt = 0
while cnt < 1000:
cnt += 1
t += 0.1
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
def init():
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 10)
del xdata[: ]
del ydata[: ]
line.set_data(xdata, ydata)
return line,
fig, ax = plt.subplots()
line, = ax.plot([ ], [ ], lw=2)
line1, = ax.plot([ ],[ ])
ax.grid()
xdata, ydata = [ ], [ ]
x1 = [ ]
y1 = [ ]
def test(x):
line1.set_data(x1,y1)
def run(data):
# update the data
t, y = data
xdata.append(t)
ydata.append(y)
xmin, xmax = ax.get_xlim()
if t >= xmax:
ax.set_xlim(xmin, 2*xmax)
ax.figure.canvas.draw()
x1 = [x + 1 for x in xdata]
y1 = [y + 1 for y in ydata]
line.set_data(xdata, ydata)
return line,
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
repeat=False, init_func=init)
ani1 = animation.FuncAnimation(fig, test, blit= False, interval =10 )
plt.show()
Sorry for being late. Yes in the example that I gave there is only one subplot. But my original requirement is two do animation in two different subplots. But to test if two FuncAnimation calls are possible I created the example with just one subplot. How is FuncAnimatation called? Is it called in a separate thread? If so can there be two separate threads for two FuncAnimation calls? Those were the questions I was wondering with. Could not find much documentation to address these questions. Appreciate any inputs