This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

work with fenics in Ipython notebook interface

+2 votes

Is it possible to execute fenics code in Ipython notebook interface?

asked Dec 12, 2013 by merinopm FEniCS Novice (370 points)

1 Answer

+3 votes
 
Best answer

Yes, definitely. I have used it on many occasions.

answered Dec 12, 2013 by logg FEniCS Expert (11,790 points)
selected Dec 13, 2013 by Garth N. Wells

would you be willing to share a notebook where I can see how to use it? :)

I would if I had one to share but I don't have any notebook stored. I use it sometimes for presentations of FEniCS (DOLFIN) demos. Then I just type the exact same lines of Python as I would in a Python terminal: from dolfin import * etc.

Is there currently any way to display plots inline (instead of in a separate window) in the IPython notebook? When working locally it's certainly no problem to have a separate plot window pop up. But when working remotely (or for sharing notebooks with other people) it would be incredibly convenient to be able to include a plot in the notebook itself (even if it's just a static snapshot without any interaction). Not sure if the current VTK-based plotting engine allows for this, but I thought it's worth asking. :)

You could save the dolfin plot to png (write_png() method I think) and then load it back into the ipython notebook interface... Not very elegant but it will work. Then you could wrap the actual calls to the dolfin plotting with a simple check to a variable, eg. if enable_interactive_plotting = True. It would be pretty simple to write a wrapper function to automate this.

Or you could generate your plots using matplotlib, these are supported natively by ipython.

...