The following code should do the trick:
import numpy as np import matplotlib.pyplot as plt from random import randint from time import sleep from ipywidgets import FloatProgress from IPython.display import display, clear_output siz = 10 dat = np.zeros((siz, siz)) fig = plt.figure() axe = fig.add_subplot(111) img = axe.imshow(dat) num = 1000 prgBar = FloatProgress(min=0, max=num-1) display(prgBar) for i in range(num): clear_output(wait = True) prgBar.value = i pos = (randint(0, siz-1), randint(0, siz-1)) dat[pos] += 1 img.set_data(dat) img.autoscale() display(fig)
I changed the for loop to create an image at each step, and also imported clear_output
to clear the cell output at each step.
source share