2017-03-26 3 views
79

क्या कोई मुझे बता सकता है कि %matplotlib inline का उपयोग वास्तव में क्या है?"% matplotlib इनलाइन" का उद्देश्य

+1

के अनुसार यह एक जादू समारोह है कि एक नोटबुक में आंकड़ा (बजाय प्रदर्शित आंकड़ा वस्तु की एक डंप) renders है। एक साधारण Matplotlib ट्यूटोरियल यहां पाया गया है https://www.data-blogger.com/2017/11/15/python-matplotlib-pyplot-a-perfect-combination/। –

उत्तर

67

%matplotlib आईपीथन में 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 क्या आप आईपीथन का उपयोग कर रहे हैं? यदि नहीं, तो आपको एक वाक्यविन्यास त्रुटि मिलेगी, क्योंकि यह वैध CPython (पायथन के लिए 'मानक' दुभाषिया नहीं है)। वैसे भी इसका उपयोग करने के लिए बहुत कम बिंदु है जब तक कि आप एक आईपथन नोटबुक का उपयोग नहीं कर रहे हैं, क्योंकि पूरे बिंदु को नोटबुक के साथ प्लॉट इनलाइन प्रस्तुत करना है। – Aurora0001

+0

हां। मैं इसका उपयोग कर रहा हूं स्पाइडर आईडीई (एनाकोंडा का हिस्सा) टेन्सफोर्लो ऑब्जेक्ट डिटेक्शन एपीआई –

17

बशर्ते आप आईपीथॉन चला रहे हों, %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.