Repository: holoviz/holoviews

Issue:
holoviews.notebook_extension() overrides %matplotlib inline
<img width="549" alt="screen shot 2017-04-18 at 20 44 55" src="https://cloud.githubusercontent.com/assets/6897215/25147471/f15c0032-2477-11e7-8a7f-4d897a1d750b.png">

```
%matplotlib inline 
import holoviews
import matplotlib.pyplot as plt
holoviews.notebook_extension()
```


Discussion:
Odd! Thanks for reporting this.

And everything is fine if you set ``%matplotlib inline`` after loading the extension?
It doesn't always work, I changed the order [here](https://gitlab.kwant-project.org/qt/topocm/commit/ec3ca877a89092ee05d26825d78c22dae5054b35), but the matplotlib plots are still missing [here](https://nbviewer.jupyter.org/url/test.topocondmat.org/notebooks/w3_pump_QHE/QHEedgestates.ipynb?flush_cache=true#Quantization-of-Hall-Conductance-from-edge-states).

Not sure if the same behaviour is reproduced by my simple example...
What's changed here is that the ``plt.switch_backend('agg')`` is now no longer executed when importing holoviews matplotlib backend instead it's executed when running ``hv.notebook_extension()``. I'd be very surprised if simply moving ``%matplotlib inline`` after the notebook extension didn't fix it. Indeed when I do this, it seems to work fine:

```python
import holoviews as hv
import numpy as np

hv.notebook_extension('matplotlib')
points = [(0.1*i, np.sin(0.1*i)) for i in range(100)]
hv.Curve(points)
```

And in a second cell:

```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

x = np.linspace(0, 1, 500)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)

fig, ax = plt.subplots()

ax.fill(x, y, zorder=10)
ax.grid(True, zorder=5)
```

Is there anything different about your setup?
Reversing the order of `hv.notebook_extension('matplotlib')` and `%matplotlib inline` only seems to fix the issue in a particular case, see the following example:


<img width="1097" alt="screen shot 2017-04-19 at 10 04 27" src="https://cloud.githubusercontent.com/assets/6897215/25169532/a9f21ef0-24e7-11e7-98c7-54a2358bfd6e.png">


**vs**


<img width="1097" alt="screen shot 2017-04-19 at 10 05 19" src="https://cloud.githubusercontent.com/assets/6897215/25169555/bbbf3ef6-24e7-11e7-95b8-82ff2e469f76.png">

You see that the order matters. So if a `holoviews` object is plotted first, the matplotlib object isn't plotted anymore.



Resolving patch:
diff --git a/holoviews/ipython/__init__.py b/holoviews/ipython/__init__.py
--- a/holoviews/ipython/__init__.py
+++ b/holoviews/ipython/__init__.py
@@ -152,6 +152,7 @@ def __call__(self, *args, **params):
             if p in self._backends:
                 imports.append((p, self._backends[p]))
         if not imports:
+            args = ['matplotlib']
             imports = [('matplotlib', 'mpl')]
 
         args = list(args)
@@ -220,6 +221,7 @@ def __call__(self, *args, **params):
         resources = list(resources)
         if len(resources) == 0: return
 
+        Renderer.load_nb()
         for r in [r for r in resources if r != 'holoviews']:
             Store.renderers[r].load_nb(inline=p.inline)
 
diff --git a/holoviews/plotting/mpl/plot.py b/holoviews/plotting/mpl/plot.py
--- a/holoviews/plotting/mpl/plot.py
+++ b/holoviews/plotting/mpl/plot.py
@@ -138,7 +138,7 @@ def __init__(self, fig=None, axis=None, **params):
         if self.renderer.interactive:
             plt.ion()
             self._close_figures = False
-        else:
+        elif not self.renderer.notebook_context:
             plt.ioff()
 
         with mpl.rc_context(rc=self.fig_rcparams):
diff --git a/holoviews/plotting/renderer.py b/holoviews/plotting/renderer.py
--- a/holoviews/plotting/renderer.py
+++ b/holoviews/plotting/renderer.py
@@ -150,6 +150,9 @@ class Renderer(Exporter):
     # Any additional JS and CSS dependencies required by a specific backend
     backend_dependencies = {}
 
+    # Whether in a notebook context, set when running Renderer.load_nb
+    notebook_context = False
+
     def __init__(self, **params):
         self.last_plot = None
         super(Renderer, self).__init__(**params)
@@ -516,3 +519,6 @@ def load_nb(cls, inline=True):
         Loads any resources required for display of plots
         in the Jupyter notebook
         """
+        with param.logging_level('ERROR'):
+            cls.notebook_context = True
+


Test patch: