Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 853
FuGeniusRy Avatar asked Mar 10 '26 22:03

FuGeniusRy


1 Answers

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()
like image 87
FuGeniusRy Avatar answered Mar 12 '26 11:03

FuGeniusRy