.fig文件是.mat文件(包含结构),请参见 http://undocumentedmatlab.com/blog/fig-files- format/
作为状态的参考,仅在v7.1之前支持结构:http ://www.scipy.org/Cookbook/Reading_mat_files
因此,在MATLAB中,我使用-v7保存:
plot([1 2],[3 4])
hgsave(gcf,'c','-v7');
然后在Python 2.6.4中,我使用:
>>> from scipy.io import loadmat
>>> x = loadmat('c.fig')
>>> x
{'hgS_070000': array([[<scipy.io.matlab.mio5.mat_struct object at 0x1500e70>]], dtype=object), '__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file, Platform: MACI64, Created on: Fri Nov 18 12:02:31 2011', '__globals__': []}
>>> x['hgS_070000'][0,0].__dict__
{'handle': array([[1]], dtype=uint8), 'children': array([[<scipy.io.matlab.mio5.mat_struct object at 0x1516030>]], dtype=object), '_fieldnames': ['type', 'handle', 'properties', 'children', 'special'], 'type': array([u'figure'], dtype='<U6'), 'properties': array([[<scipy.io.matlab.mio5.mat_struct object at 0x1500fb0>]], dtype=object), 'special': array([], shape=(1, 0), dtype=float64)}
我.__dict__
以前在哪里查看如何遍历结构。例如XData
,YData
我可以使用:
>>> x['hgS_070000'][0,0].children[0,0].children[0,0].properties[0,0].XData
array([[1, 2]], dtype=uint8)
>>> x['hgS_070000'][0,0].children[0,0].children[0,0].properties[0,0].YData
array([[3, 4]], dtype=uint8)
证明我plot([1 2],[3 4])
在MATLAB中使用过(孩子是轴,孙子是线系列)。