i want to plot two animated functions on the same plot to compare between two functions , lets say for example exp(-x2) and exp(x2) i know how to animate a function here is the code i used to animate the function
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
%matplotlib qt
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'r', animated=True)
f = np.linspace(-3, 3, 200)
def init():
ax.set_xlim(-3, 3)
ax.set_ylim(-0.25, 2)
ln.set_data(xdata,ydata)
return ln,
def update(frame):
xdata.append(frame)
ydata.append(np.exp(-frame**2))
ln.set_data(xdata, ydata)
return ln,
ani = FuncAnimation(fig, update, frames=f,enter code here
init_func=init, blit=True, interval = 2.5,repeat=False)
plt.show()
enter code here
and by the same method we can plot the other function but how do we show them on the same plot

ln2, = plt.plot(...)and update that line in the same way you're doing it forlnalready.