Jupyter notebook: Displaying multiple plots from within a loop

I am running the code from this tutorial in a Jupyter notebook. The loop

for n in range(num_steps):
    # Update current time
    t += dt
    u_D.t = t
    # Compute solution
    solve(a == L, u, bc)
    # Plot solution
    plot(u)
    # ...

ought to generate multiple plots, but only one is rendered in the notebook.
In the past, I’ve used the code

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

to enable the display of multiple outputs from a single cell.
But that does not work here. How can I see all the plots?

I’m sure other people with more experience will show up soon, in the meantime:

At first glance, these demos are very outdated. I can see that it’s still using the old VTK backend of dolfin which was removed in around 2015 due to maintenance issues. This is indicated by the interactive() function.

It’s typically recommended to output data to file for visualisation with more sophisticated packages, e.g: Paraview or Visit.

Since you’re using Jupyter notebooks I’ll assume this isn’t an option, so two options spring to mind:

  • Use the build in matplotlib support via dolfin.plot.
  • The excellent vedo package. There are some examples using dolfin in the notebooks directory.

Thanks, Nate. I’ll give those a try.

I must say, though, that I’m surprised by your statement that VTK support was removed c.2015. This tutorial, which is linked to on the FEniCS tutorial page, is dated September 2017. If possible, would you (or anyone else here) point me (and other newbies) to a more up-to-date FEniCS tutorial.

The fenics tutorial is a book released in 2017, and was tested against the fenics 2016.2.0 version, which is one of the last versions of fenics with VTK support.
The authors of the book does unfortunately no longer actively participate in the fenics enviroment, and thus there has not been issued an updated version.
There are alot of documented demos for fenics, see: https://fenicsproject.org/docs/dolfin/latest/python/demos.html
There is also a large set of undocumented demos at https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/undocumented/