How do I run Matlab from Python, but save figures to a file?
Afficher commentaires plus anciens
I am successfully running Matlab from Python. The Matlab code I have displays 2 figures. Upon running Python, would rather those figures go to a file. Is there a switch, or some such option to get that to happen? Rather not rewrite Matlab code with some sort of Python specific switch.
Thanks, Tom
2 commentaires
Image Analyst
le 17 Oct 2015
Why would you need a Python specific switch? Why not just save the figures using export_fig() directly from MATLAB?
Tom McGiffen
le 19 Oct 2015
Réponses (2)
Bo Li
le 19 Oct 2015
There is no such flag. Python Engine allows you to have full control over MATLAB from Python. You can simply save a figure like following example shows:
>>>eng.plot(matlab.double([1,2,3,4])) %create a plot
>>>eng.savefig("foo.fig",nargout=0) %save current figure to "foo.fig"
>>>eng.close() %close current figure
3 commentaires
Tom McGiffen
le 19 Oct 2015
Bo Li
le 19 Oct 2015
Yes, I believe it works for Linux and Mac:
Start up options can be also used in Python Engine. For example, you can start MATLAB with "-nodisplay" by:
>>> eng = matlab.engine.start_matlab("-nodisplay")
Bo Li
le 19 Oct 2015
You probably can try the start up option "-noFigureWindows" if the purpose is to hide the figure window:
This works on all platforms.
Nicholas G
le 18 Sep 2019
0 votes
Why the figure turn off automatically after it show up?
1 commentaire
Tianya Duan
le 24 Mar 2020
I also have this question, do you have solve it?
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!