Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

%matplotlib inline doesn't work on iPython and Jupyter console

I'm trying out Jupyter console for the first time, but can't get the %matplotlib inline magic to work. Below is a screenshot of an example session:

The window is a result of Line 6, and Line 7 didn't do anything at all. The plot shows in a separate window after I run Line 6, and Line 7 doesn't do anything.

When I run %matplotlib --list, inline is given as one of the options:

Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt',
'nbagg', 'agg', 'gtk', 'tk', 'ipympl', 'inline']

When I try to use another backend, say qt5, it gives an error message because I don't have any Qt installed.

ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide
package to be installed, but it was not found.

Running %matplotlib?? reads:

 If you are using the inline matplotlib backend in the IPython Notebook
        you can set which figure formats are enabled using the following::

            In [1]: from IPython.display import set_matplotlib_formats

            In [2]: set_matplotlib_formats('pdf', 'svg')

        The default for inline figures sets `bbox_inches` to 'tight'. This can
        cause discrepancies between the displayed image and the identical
        image created using `savefig`. This behavior can be disabled using the
        `%config` magic::

            In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}

But I don't know if it's something I can tweak around to solve my issue.

When I try it the magic IPython console, it says inline is an Unknown Backend.

UnknownBackend: No event loop integration for u'inline'. Supported event loops are: qt, 
qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx

I've also found this issue on github after some googling but I don't even know if it's relevant to my situation (most of their conversation didn't make sense to me lol).

Lastly, I'm not sure if this issue is related at all, but here it is, just in case: when I try to open Vim in Jupyter via the !vim command, it glitches pretty badly, preventing me from even exiting out of Jupyter itself without closing the terminal altogther. Vim works perfectly fine when called inside IPython console, however.

I'm using matplotlib 2.0.0.

If anyone could help me figure this out, that'd be great! Thank you!

like image 388
spicypumpkin Avatar asked Mar 06 '17 02:03

spicypumpkin


2 Answers

%matplotlib without the inline works for me (I'm using osx and IPython 7.0.1)

like image 71
Peter Evan Deal Avatar answered Nov 18 '22 13:11

Peter Evan Deal


You’re running a console which is completely text based and incapable of showing images. Therefore, although inline is available, it's not producing inline output.

I'm not sure why it doesn't throw an error, though, which it does in my case:

enter image description here

You can use %matplotlib inline in a GUI console, like Jupyter QTConsole

enter image description here

or in a jupyter notebook in the browser

enter image description here

like image 14
ImportanceOfBeingErnest Avatar answered Nov 18 '22 14:11

ImportanceOfBeingErnest