MATLAB: Is it possible to display a MATLAB plot in python

guilibrary compilerMATLAB CompilerMATLAB Compiler SDKplotpython

I found one example with the Compiler SDK for Java here, but none for a python application.
I tried to package the following code to a python module via the Librabry Compiler (Compiler SDK):
function drawplot(x,y)
plot(x,y);
I installed the module and then tried to call the function in Python:
import PlotDrawer
myPlotter = PlotDrawer.initialize()
myPlotter = PlotDrawer.drawplot(5,5)
The import works, but I get this error:
AttributeError: module 'PlotDrawer' has no attribute 'drawplot'
When I don't use plots like in this example I don't get any errors and it works just fine. My guess is that MATLAB Library Compiler ignores functions with graphical functions in it. Is it even possible to display a MATLAB Plot in Python via the Compiler SDK?
I have the code written already in MATLAB and want to create a GUI in Python (for more flexibility and better, professional appearance). Any other approaches?
Thanks in Advance!

Best Answer

There are two things I found in your codes.
  1. After initialization, you need to use the same variable name ( myPlotter) in your python script.
  2. The number of output from drawplot function is 0, so you need to specify nargout=0 in the function call.
Here's the Python code which will display MATLAB figure.
import PlotDrawer
myPlotter = PlotDrawer.initialize()
myPlotter.drawplot(5, 5, nargout=0)
Also, if want to input arrays, matlab.double is available by importing matlab.
The following python code will dipslay 2D line plot.
import PlotDrawer
import matlab
myPlotter = PlotDrawer.initialize()
x = matlab.double([1,2,3,4,5])
y = matlab.double([1,2,3,4,5])
myPlotter.drawplot(x, y, nargout=0)
Also, there's a user's guide for MATLAB Compiler SDK for Python, which might help you.