pythonwolfram-mathematica

Show a Wolfram Mathematica Plot from within Python


I need to show a plot created by the Wolfram Mathematica application used from within a Python script.

So far I have written the following code, but I do not know how I should show the information stored in the wlplot variable. Is it even possible in Python? The plot.txt file contains the command I need. I checked that the command is correct and that it is properly executed in the Wolfram Alpha itself.

session = WolframLanguageSession()
plot_file = open("plot.txt")
wl_comm = plot_file.read()
plot_file.close()
wlplot = session.evaluate(wlexpr(wl_plot))
#???
session.terminate()

So the question is: If it is possible, what should I write within the Python script in order to show the plot created by the Wolfram Engine?


Solution

  • The working code follows.

    from PIL import Image
    
    png_export = wl.Export(path,wlplot,"PNG")
    session.evaluate(png_export)
    img = Image.open(path)
    img.show()