How to display images inside Mathematica with matplotlib.
A new window is generated by default, but is it possible to display the picture directly in the notebook?
Like this:
related: How to display images and plots from ExternalEvaluator?
How to display images inside Mathematica with matplotlib.
A new window is generated by default, but is it possible to display the picture directly in the notebook?
Like this:
related: How to display images and plots from ExternalEvaluator?
Seems to be able to embed images by converting to png.
import io
from PIL import Image
import matplotlib.pyplot as plt
def show_plt(plot):
buf = io.BytesIO()
plot.savefig(buf, transparent=True, format='png')
buf.seek(0)
im = Image.open(buf).convert("RGBA")
buf.close()
return im
In fact, matplotlib can export svg, but wolfram does not support importing svg, so there is no way to get vector graphics.
Note that this function works for all libraries that depend on matplotlib, like seaborn: