Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ipython notebook: show for-loop images "realtime", before next step [duplicate]

Running following code in an ipython/jupyter notebook:

for i in range(4):

    # any figure
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(range(i), range(i))
    fig.show()

    # do something that takes a long time:
    a = fib(500000)     

results in all the figures being visible at the same time (after the 4th loop).

How can I change my setup so that the figures become visible as soon as they have been calculated (before the next step in the for loop)?

N.B. I'm using %matplotlib inline

like image 806
Daniel Power Avatar asked Nov 09 '15 15:11

Daniel Power


1 Answers

First, import display:

from IPython import display

and replace fig.show() by display.display(fig)

like image 171
jrjc Avatar answered Oct 10 '22 15:10

jrjc