2017-03-26 5 views
79

誰かが正確に%matplotlib inlineの使用を教えてもらえますか?"%matplotlib inline"の目的

+1

によると、これは、(代わりにFigureオブジェクトのダンプを表示する)、ノートブックの図を描画する魔法の関数です。 Matplotlibの簡単なチュートリアルはhttps://www.data-blogger.com/2017/11/15/python-matplotlib-pyplot-a-perfect-combination/にあります。 –

答えて

67

%matplotlibは、IPythonのmagic functionです。 「インライン」のバックエンドを使用する場合は、あなたのmatplotlibのグラフは、お使いのノートブックに含まれます

With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.

IPython has a set of predefined ‘magic functions’ that you can call with a command line style syntax. There are two kinds of magics, line-oriented and cell-oriented. Line magics are prefixed with the % character and work much like OS command-line calls: they get as an argument the rest of the line, where arguments are passed without parentheses or quotes. Lines magics can return results and can be used in the right hand side of an assignment. Cell magics are prefixed with a double %%, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument.

%matplotlib inlinesets the backend of matplotlib to the 'inline' backend:私はあなたの便宜のために読めるのはここでは関係の文書を引用しますコードの横に表示されます。コードでの使用方法については、How to make IPython notebook matplotlib plot inlineも参考にしてください。

インタラクティブ機能を使用する場合は、hereのように、nbagg backend%matplotlib notebook(IPython 3.x)で使用できます。

+1

%matplotlibインライン ^ SyntaxError:無効な構文 –

+0

@Jadda IPythonを使用していますか?そうでなければ、有効なCPython(Python用の '標準'インタープリタ)ではないため、構文エラーが発生します。あなたがIPython Notebookを使用しているのでなければ、それを使っている点はほとんどありません。ノート全体をプロットして描画することがポイントです。 – Aurora0001

+0

はい。私はTensorflowオブジェクト検出APIを実装するためにSpyder IDE(Anacondaの一部)でこれを使用しています –

17

あなたがIPythonを実行している場合、%matplotlib inlineはプロット出力を表示してノートブックに保存します。

documentation

To set this up, before any plotting or import of matplotlib is performed you must execute the %matplotlib magic command . This performs the necessary behind-the-scenes setup for IPython to work correctly hand in hand with matplotlib ; it does not, however, actually execute any Python import commands, that is, no names are added to the namespace.

A particularly interesting backend, provided by IPython, is the inline backend. This is available only for the Jupyter Notebook and the Jupyter QtConsole. It can be invoked as follows:

%matplotlib inline 

With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.

関連する問題