title: jupyter notebook - matplotlib shows figure even without calling plt.show()
body: <p>The following is a simplified example of my code. The idea behind this class is to show the figure only when the <code>show</code> method is executed.</p>
  <pre class="lang-py prettyprint-override"><code># my_module.py
  import matplotlib.pyplot as plt
  import numpy as np
  
  class Test:
      def __init__(self):
          self._fig = plt.figure()
          self.ax = self._fig.add_subplot(1, 1, 1)
  
      def show(self):
          x = np.linspace(0, 10, 100)
          y = np.sin(x)
          self.ax.plot(x, y)
          self._fig.tight_layout()
          self._fig.show()
  </code></pre>
  <p>The code works as expected when it is executed from a Python shell or ipython. However, if I run this inside a Jypter Notebook:</p>
  <pre class="lang-py prettyprint-override"><code>from my_module import Test
  t = Test()
  </code></pre>
  <p>At this point, an empty figure is visualized on the screen. I don't want that! Now, I tried to insert <code>plt.close(self._fig)</code> inside <code>__init__</code>, but then when I run <code>t.show()</code> I get <code>UserWarning: Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.</code></p>
  <p>I also tried to load <code>%matplotlib widget</code> with the previous edit <code>plt.close(self._fig)</code>. The pictures is only shown when <code>show</code> is called, but it is just a picture with no interactive frame.</p>
  <p>Another option would be to rewrite the class in such a way that the figure is created inside the <code>show</code> method. This is far from optimal as I would need to re-adjust my tests.</p>
  <p>Are there any other ways to get it working correctly on all shells?</p>