11

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!

1
  • Jupyter notebook is different from console. %matplotlib inline is notebook specific.
    – Mr. Hobo
    Commented Mar 6 at 10:52

4 Answers 4

16

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

1
  • I actually got the same error when I first tried it, but somehow was able to get around it. I don't remember what exactly I did, though. Anyways thank you so much, it was so obvious but I don't know why I didn't realize that.. haha. Commented Mar 6, 2017 at 9:00
3

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

2
  • update: I'm using IPython 7.6.1 and %matplotlib doesn't seem to work for me anymore. Commented Jul 11, 2019 at 22:19
  • Like Brad said, you can't put inline images into a console... but I believe %matplotlib inline does have an effect on most systems - without it, you need plt.show() to display a graph in an external window, and it blocks input to the console until you close it. With %matplotlib inline you don't need plt.show() and it doesn't block the console. It's also worth noting that you use %matplotlib osx on MacOS rather than inline. Commented Jul 11, 2019 at 22:27
0

If you're running an old version of ipython try %pylab inline instead. See notes in this tutorial

0
0

In newer matplotlib and jupyter versions, this works for me:

import matplotlib_inline

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 6 at 10:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.