필터 지우기
필터 지우기

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

조회 수: 30 (최근 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
Image Analyst
Image Analyst 2015년 10월 17일
Why would you need a Python specific switch? Why not just save the figures using export_fig() directly from MATLAB?
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일
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
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?

카테고리

Help CenterFile Exchange에서 Python Package Integration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by