Message Boards Message Boards

Use ResourceFunction with the Wolfram Client Library for Python

Posted 5 years ago

Hey Everyone, (ps: thank you in advance)

How do I write :

ResourceFunction["MultiwaySystem"][{"A" -> "B","A" -> "C","B" -> "DA", "C" -> "DA","DA"->"B"}, "A", 8, "CausalGraph"]

with The Wolfram Client Library for Python?

POSTED BY: leo vad
2 Replies

Hello Leo!

For writing that in the WolframClientLibraryForPython, you can do that by using the WolframLanguageSession and wlexpr. Executing the code is pretty straightforward, but displaying the graphics is more tricky since there's no display for the graph in the python language. So the method I used is to rasterize the image and display it with matplotlib.

Python3 Kernel on JupyterLab

Here's the code.

import matplotlib.pyplot as plt

from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr
session = WolframLanguageSession()

graph = session.evaluate(wlexpr('ResourceFunction["MultiwaySystem"][{"A" -> "B","A" -> "C","B" -> "DA", "C" -> "DA","DA"->"B"}, "A", 8, "CausalGraph"] // Rasterize'))

plt.imshow(graph[0])
POSTED BY: Pedro Cabral
Posted 5 years ago

Thank you Pedro Cabral. Everything work perfectly and i fix the problem of rasterize the image. The only problem is the size of the edge ( i'm only able to change it to a shape and resize it , not resize the original. can't resize the label)
enter image description here

import matplotlib.pyplot as plt

from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr
session = WolframLanguageSession()

graph = session.evaluate(wlexpr('Image[ResourceFunction["MultiwaySystem"][{"A" -> "B","A" -> "C","B" -> "DA", "C" -> "DA","DA"->"B"}, "A", 8, "CausalGraph"],ImageSize -> {1920, 1080}]'))

plt.figure(figsize = (100,100))
img = plt.imshow(graph[0])
plt.show(img)
POSTED BY: leo vad
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract