I am simulating a differential equation evolving in time in a Python Jupyter notebook using the script below:
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import clear_output
L = 100
x_positions = np.linspace(0, L, 1001)
for t in range(1, 100):
mass = np.zeros(1001)
plt.ioff()
for n in range(-5, 5):
mass += [np.exp(-(x + 2 * n * L) ** 2 / (4 * t)) for x in x_positions]
plt.scatter(mass, x_positions)
clear_output()
plt.show()
plt.pause(0.1)
However, the Jupyter notebook cell refreshes each time the plot updates, which creates unnecessary scrolling and blinking. Is there a better way to prevent this behavior?