I am trying to translate the following MATLAB code to Python. In MATLAB, the code dynamically updates a single plot for multiple iterations (n = 1:100), and each update displays the interpolation alongside the original function.
for n = 1:100
[err, t, f, x, p] = intlag(n);
plot(x, sin(x), '-r', x, p, '-b'); % 1./(5*x.*x+1)
axis([-1 1 -2 2])
legend('fonction', 'interpolant')
title(['t = ', num2str(n)])
drawnow
end
I attempted to use matplotlib with plt.ion() and plt.pause(), but I couldn't achieve the same smooth dynamic updates. Also, I want to ensure that all updates occur in a single figure.
Can someone help me write a Python equivalent for this functionality?

FuncAnimation?