How to check that pylab backend of matplotlib runs inline?

ipython, jupyter-notebook, matplotlib, python

Solution

You can check the matplotlib backend with:

import matplotlib
matplotlib.get_backend()

To check for inline matplotlib in particular:

mpl_is_inline = 'inline' in matplotlib.get_backend()

Note that with the IPython notebook, you can always display inline figures, regardless of the active matplotlib backend, with:

display(fig)

Problem

I am modifying a python module that plots some special graphs using matplotlib. Right now, this module just saves all figures as files. I would like to make it possible to import the module while working in ipython notebook and see the results "inline", on the other hand I would like to keep the default functionality of saving the figures as files when the module is imported in all other cases. So I need somehow to check if the module is imported in ipython notebook and the pylab is operating inline or not. How can I check this?

Original source