Python Saving PNG in Terminal vs IPython Notebook
<p>I am writing a basic Python module which contains a function that plots some data from a Pandas DataFrame.  The problem is that I expect users to call this function from <em>both</em> the interactive shell <em>and</em> IPython notebooks.  Unfortunately, our interactive shell environment does not have any valid DISPLAY options for matplotlib to use, so I want my function (or the full module) to behave slightly different depending on which environment it is loaded into.  (E.g., the default is show the plot without saving in IPython, and save the plot without showing in the shell).</p>

<p><a href="https://stackoverflow.com/questions/2801882/generating-a-png-with-matplotlib-when-display-is-undefined">This question</a> gives me a partial answer, in that I can explicitly tell users to write <code>matplotlib.use('Agg')</code> before they ever import my module, but surely there is a more automated backend way to handle this?</p>