我知道在 R 中你可以输入 ?"function_name"。你如何在python中做到这一点?具体来说,我正在尝试set_position
在pyplot
图书馆中查找有关信息。
问问题
143 次
3 回答
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)
于 2013-02-22T17:05:47.823 回答
3
尝试运行ipython
,在这种情况下,您可以键入:
In [1]: from matplotlib import pyplot as pl
In [2]: pl.set_position?
Object `pl.set_position` not found.
在这里,您必须使用google找出这set_position
是Axes
该类的方法:
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
========== ====================
于 2013-02-22T17:14:36.727 回答
2
在ipython
它的超级简单中 - 只需将?
(或??
使用源代码的扩展信息)附加到有问题的函数。
我总是在以交互方式工作时使用它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]:
于 2013-02-22T17:12:38.587 回答