[SciPy-User] loadmat and figure

Fabrice Silva silva@lma.cnrs-mrs...
Sun Aug 5 05:29:31 CDT 2012

Le dimanche 05 août 2012 à 11:50 +0200, x.piter@gmail.com a écrit :
> Hi
> Fabrice Silva <silva@lma.cnrs-mrs.fr> writes:
> > Are not matlab figure supposed to be .fig files ?
> > The 'a' items of the resulting dictionary seems weird.
> I was not sure if fig files are compartiple with loadmat, so I had
> loaded figure in matlab with -mat key and saved the structure a.mat

Debian unstable ships scipy 0.10 which succeed in loading .fig files.
Example :

        In [1]: import scipy; scipy.__version__
        Out[1]: '0.10.1'
        In [2]: import scipy.io as io
        In [3]: d = io.loadmat('AR.fig', squeeze_me=True, struct_as_record=False); d.keys()
        Out[3]: ['hgS_070000', '__version__', '__header__', '__globals__']
Note the hgS_* magic key indicating matlab v7 figure type
        In [4]: print d['__header__']
        MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Fri Jul  6 13:43:19 2012 
        In [5]: print d['hgS_070000'].type
You then need to introspect through the structured hierarchy to extract your data
        In [6]: print d['hgS_070000'].children.type
        In [7]: print d['hgS_070000'].children.children.shape
        In [8]: print d['hgS_070000'].children.children[0].type
        In [9]: dir(d['hgS_070000'].children.children[0].properties)
Getting X and Y arrays for the first line of the first axes
        In [10]: X = d['hgS_070000'].children.children[0].properties.XData
        In [11]: Y = d['hgS_070000'].children.children[0].properties.YData
        In [12]: import matplotlib.pyplot as plt
        In [13]: plt.plot(X,Y)
        Out[13]: [<matplotlib.lines.Line2D at 0xa164b8c>]

> This is another trouble but I will think about it when I reach this
> stage (I need only numbers). May be I need the latest scipy.

Have you seen the note at the end of this page, concerning v7.3 format
not handled by scipy 0.7 (also neither by recent versions) ?

Fabrice Silva <silva@lma.cnrs-mrs.fr>

More information about the SciPy-User mailing list