1

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

enter image description here

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?

2
  • Does Matlab clear the plot before each new update or does it accumulate? Commented Jan 7 at 20:45
  • Is there a reason you want to use this approach over FuncAnimation? Commented Jan 7 at 20:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.