而不是通過一個字符串,您可以直接訪問該信息,我認爲這是更清潔:
>>> print a
Axes(0.547727,0.536364;0.352273x0.363636)
>>> a._position.bounds
(0.54772727272727262, 0.53636363636363638, 0.35227272727272729, 0.36363636363636365)
>>> a._position.bounds[3]
0.36363636363636365
雖然你可以有字符串,如果你喜歡:
>>> str(a)
'Axes(0.547727,0.536364;0.352273x0.363636)'
>>> str(a)[5:-1]
'0.547727,0.536364;0.352273x0.363636'
我使用IPython的解釋,所以很容易通過在源尋找a.__str__
找出其中的信息來自何處:
>>> a.__str__??
Type: instancemethod
String Form:<bound method AxesSubplot.__str__ of <matplotlib.axes.AxesSubplot object at 0x103e187d0>>
File: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py
Definition: a.__str__(self)
Source:
def __str__(self):
return "Axes(%g,%g;%gx%g)" % tuple(self._position.bounds)
來源
2013-05-17 11:46:07
DSM
完美,這正是我正在尋找的!非常感謝! – bserra