I’m trying to create a pyplot simulation using plt.pause() but I can’t make even the simplest example work. This is the code:
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(19680801)
data = np.random.random((50, 50, 50))
fig, ax = plt.subplots()
for i, img in enumerate(data):
ax.clear()
ax.imshow(img)
ax.set_title(f"frame {i}")
plt.pause(0.1)
The issue seems to have something to do with the last line of code (plt.pause(0.1)). Without this line the final output shows the final frame of the simulation—frame 49 (indicating the whole loop has finished). If I include the final line and run the simulation, the output stops at the first frame—frame 0 (and the simulation doesn’t progress to the next step in the loop). I’ve also tried to set plt.pause(0.0) but that had exactly same effect as setting it to any other number.
I’m on mac, using python 3.12 under jupyter notebook 7.2.1. I would appreciate any advice. Thank you.