The MATLAB .fig file is nothing more than a MAT-file that contains each of the handle graphics objects in the figure, complete with all their properties. MATLAB handle graphics objects are class objects whose type determines what graphic to draw, and whose properties determines how to draw it.
For example a line plot will have a figure object, containing an axes object, containing a line object. The line object will have xdata
and ydata
properties containing the data plotted. But each of these objects has many, many properties that need to be set. For example, the line also has properties for color and width, which markers to use and how to draw those, etc.
We can write a MAT-file in Python using scipy.io.savemat
. But generating the data to be saved will be a lot of work. We would have to take each of the Matplotlib objects in the figure we wish to save (which have a similar hierarchy to MATLAB’s), and translate their properties to how MATLAB represents them in their objects. This will involve research for each graphics object type, since they all have a different set of properties.
Writing a function to create a .fig file from a Matplotlib plot would be possible, but not worth the effort, IMO. It would be easier to save the data and translate the Python script that generates the plot to a MATLAB script to generate the equivalent plot in MATLAB.