2017-03-26 1 views
79

의 목적 누군가 정확히 %matplotlib inline의 사용법을 설명 할 수 있습니까?"% matplotlib inline"

+1

따르면 이것은 노트북 그림 (대신 표시 도형 객체의 덤프) 렌더링 마법 함수이다. 간단한 Matplotlib 튜토리얼은 https://www.data-blogger.com/2017/11/15/python-matplotlib-pyplot-a-perfect-combination/에서 찾을 수 있습니다. –

답변

67

%matplotlib은 IPython에서 magic function입니다. 나는 편의를 위해 읽는 당신을 위해 여기에 관련 문서를 인용합니다 :

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을 :

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.

'인라인'백엔드를 사용하여하기 matplotlib 그래프가 노트북에 포함됩니다, 코드 옆에. 코드에서 사용하는 방법에 대한 참조는 How to make IPython notebook matplotlib plot inline을 읽어 보는 것도 좋습니다.

상호 작용을 원할 경우 here과 같이 nbagg backend%matplotlib notebook (IPython 3.x)과 함께 사용할 수 있습니다.

+1

% matplotlib 인라인 ^ 구문 오류 : 잘못된 구문 –

+0

@Jadda IPython을 사용하고 있습니까? 그렇지 않다면 유효한 CPython (Python의 '표준'인터프리터)이 아니기 때문에 구문 오류가 발생합니다. 어쨌든 IPython Notebook을 사용하지 않는 한 거의 사용하지 않는 점이 있습니다. 요점은 노트북을 사용하여 플롯을 인라인으로 렌더링하는 것입니다. – Aurora0001

+0

예. Spyder IDE (Anaconda의 일부)를 사용하여 Tensorflow Object Detection API를 구현합니다. –

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.