2013-02-22 72 views

回答

8
help(function) 

應該這樣做。

演示:

def func(): 
    """ 
    I am a function who doesn't do anything, 
    I just sit in your namespace and crowd it up. 
    If you call me expecting anything 
    I'll just return to you the singleton None 
    """ 
    pass 

help(func) 
+0

所以我輸入pyplot作爲plt。我想調整我的情節的位置。當我輸入help(pl.set_position)或help(set_position)時,我收到一條錯誤消息。 – lord12 2013-02-22 17:08:57

+0

@ lord12 - 這是因爲'plt.set_position'不存在...您首先需要知道哪裏可以找到您的功能。 – mgilson 2013-02-22 17:10:59

+1

接受提案以更好地編寫文檔串的最後一行--- http://www.youtube.com/watch?v=XaWU1CmrJNc – mgilson 2013-02-22 17:12:02

2

ipython其supereasy - 只是追加?(或??用於與源代碼的擴展信息)到所討論的功能。

matplotlib交互工作時,總是使用它:

In [2]: from matplotlib.axes import Axes 

In [3]: Axes.set_position?? 
Type:  instancemethod 
String Form:<unbound method Axes.set_position> 
File:  /home/tzelleke/.local/modules/active_python_2.7/lib/python2.7/site-packages/matplotlib/axes.py 
Definition: Axes.set_position(self, pos, which='both') 
Source: 
    def set_position(self, pos, which='both'): 
     """ 
     Set the axes position with:: 

      pos = [left, bottom, width, height] 

     in relative 0,1 coords, or *pos* can be a 
     :class:`~matplotlib.transforms.Bbox` 

     There are two position variables: one which is ultimately 
     used, but which may be modified by :meth:`apply_aspect`, and a 
     second which is the starting point for :meth:`apply_aspect`. 


     Optional keyword arguments: 
      *which* 

      ========== ==================== 
      value  description 
      ========== ==================== 
      'active'  to change the first 
      'original' to change the second 
      'both'  to change both 
      ========== ==================== 

     """ 
     if not isinstance(pos, mtransforms.BboxBase): 
      pos = mtransforms.Bbox.from_bounds(*pos) 
     if which in ('both', 'active'): 
      self._position.set(pos) 
     if which in ('both', 'original'): 
      self._originalPosition.set(pos) 

In [4]: 
3

嘗試在ipython運行,在這種情況下,你可以輸入:

In [1]: from matplotlib import pyplot as pl 

In [2]: pl.set_position? 
Object `pl.set_position` not found. 

在這裏,你必須使用google找出set_positionAxes類的一種方法:

In [3]: pl.Axes.set_position? 
Type:  instancemethod 
String Form:<unbound method Axes.set_position> 
File:  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py 
Definition: pl.Axes.set_position(self, pos, which='both') 
Docstring: 
Set the axes position with:: 

    pos = [left, bottom, width, height] 

in relative 0,1 coords, or *pos* can be a 
:class:`~matplotlib.transforms.Bbox` 

There are two position variables: one which is ultimately 
used, but which may be modified by :meth:`apply_aspect`, and a 
second which is the starting point for :meth:`apply_aspect`. 


Optional keyword arguments: 
    *which* 

    ========== ==================== 
    value  description 
    ========== ==================== 
    'active'  to change the first 
    'original' to change the second 
    'both'  to change both 
    ========== ==================== 
相關問題