How do I run Matlab from Python, but save figures to a file?

21 ビュー (過去 30 日間)
Tom McGiffen
Tom McGiffen 2015 年 10 月 17 日
コメント済み: Tianya Duan 2020 年 3 月 24 日
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 件のコメント
Tom McGiffen
Tom McGiffen 2015 年 10 月 19 日
I am calling an existing codebase we do not want to modify... am working a larger project. The existing codebase makes the figures. Want that in stand-alone, don't want it when called externally.

サインインしてコメントする。

回答 (2 件)

Bo Li
Bo Li 2015 年 10 月 19 日
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 件のコメント
Bo Li
Bo Li 2015 年 10 月 19 日
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
Nicholas G 2019 年 9 月 18 日
Why the figure turn off automatically after it show up?
  1 件のコメント
Tianya Duan
Tianya Duan 2020 年 3 月 24 日
I also have this question, do you have solve it?

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by