2017-03-06 206 views
1

我第一次嘗試Jupyter控制檯,但無法獲得%matplotlib inline魔法的工作。下面是一個示例會話的屏幕截圖:%matplotlib inline不能在iPython和Jupyter控制檯上工作

The window is a result of Line 6, and Line 7 didn't do anything at all. 在我運行第6行後,該圖顯示在一個單獨的窗口中,第7行沒有執行任何操作。

當我運行%matplotlib --listinline給出的選項之一:

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

當我嘗試使用其他後端,說qt5,是因爲我沒有安裝任何的Qt不給出錯誤信息。

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

運行%matplotlib??寫着:

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} 

但我不知道這件事情我可以調整左右來解決我的問題。

當我試用它的魔術IPython控制檯時,它說inlineUnknown Backend

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

我也發現了一些谷歌上搜索後this issue on github但我甚至不知道這是否是有關我的情況(大多數他們的談話沒有意義,我大聲笑)。最後,我不確定這個問題是否完全相關,但在這裏,以防萬一:當我嘗試通過!vim命令在Jupyter中打開Vim時,它會非常糟糕地發生故障,阻止我甚至不能退出Jupyter本身而不關閉終端altogther。但是,在IPython控制檯內部調用Vim時,它工作得很好。我正在使用matplotlib 2.0.0

如果有人能幫我弄清楚,那太棒了!謝謝!

回答

5

您正在運行完全基於文本且無法顯示圖像的控制檯。因此,儘管inline可用,但它不會生成內聯輸出。

我不知道爲什麼它不拋出一個錯誤,雖然它一定在我的情況:

enter image description here

您可以在GUI控制檯使用%matplotlib inline,像Jupyter QTConsole

enter image description here

或在瀏覽器中的筆記本jupyter

enter image description here

+0

實際上,我第一次嘗試它時遇到了同樣的錯誤,但以某種方式能夠避開它。不過,我不記得我做了什麼。無論如何非常感謝你,這是如此明顯,但我不知道爲什麼我沒有意識到這一點..哈哈。 – spicypumpkin

相關問題