Interactive plot in Jupyter notebook

Viewed 6651

I am trying to get 'realtime' ploting in Jupyter notebook. The example can be found here. Here is the code:

%matplotlib notebook

import numpy as np
import matplotlib.pyplot as pl

from random import randint
from time import sleep

from ipywidgets import FloatProgress
from IPython import display

siz = 10
dat = np.zeros((siz, siz))

fig = pl.figure()
axe = fig.add_subplot(111)
img = axe.imshow(dat)

num = 1000

prgBar = FloatProgress(min=0, max=num-1)
display.display(prgBar)

for i in range(num):
    prgBar.value = i
    pos = (randint(0, siz-1), randint(0, siz-1))
    dat[pos] += 1
    img.set_data(dat)
    img.autoscale()
    #sleep(0.01)

What I am aiming for is to see how the plot is changing with each itteration. I also tried set the interactive mod on by pl.ion(), changing backent to inline, calling pl.draw(), but non of it was working. BTW, the progressbar is working just fine...

Thanks Radek

1 Answers
Related