I'm writing some software that creates matplotlib plots of simulation data. Since these plotting routines are often running in a headless environment, I've chosen to use the matplotlib object oriented interface explicitly assign canvases to figures only just before they are saved. This means I cannot use pylab or pyplot based solutions for this issue.
I've added some special sauce so the plots show up inline either by invoking a display
method on the plot object or by invoking __repr__
. However, the check I'm doing to determine if a user is running under IPython (checking for "__IPYTHON__" in dir(__builtin__)
) cannot discriminate whether the user is in a notebook or just a regular terminal session where inline figures won't work.
Is there some way to programatically check whether a code snippet has been executed in a notebook, qt console, or terminal IPython session? Am I doing something silly here - I haven't looked too closely at the display semantics so perhaps I'm ignorant about some portion of the IPython internal API that will take care of this for me.