您可以直接访问该信息,而不是通过字符串,我认为这更干净:
>>> 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)