7

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

Daniel Power
  • 645
  • 9
  • 22
  • 2
    Duplicated several times: [here](https://stackoverflow.com/questions/21360361/how-to-dynamically-update-a-plot-in-a-loop-in-ipython-notebook-within-one-cell), [here](https://stackoverflow.com/questions/32051408/dynamically-update-plot-in-ipython-notebook)... – Imanol Luengo Nov 10 '15 at 10:09

1 Answers1

4

First, import display:

from IPython import display

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

jrjc
  • 21,103
  • 9
  • 64
  • 78