Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

When I try t display the Plotly graph from python as an image that works fine

import plotly.express as px

from IPython.display import Image

fig = px.scatter(x=range(10), y=range(10))

Image(fig.to_image(format="png"))

However, when I try the same via embedpy from jupyterq, the graph won't display

px:.p.import[`plotly.express]

ipd:.p.import[`IPython.display]

fig:px[`:scatter][`x pykw til 10; `y pykw til 10]

img:fig[`:to_image][`format pykw `png]

ipd[`:Image][img]

The graph won't display. I also tried actively displaying it, but this just shows tiny generic image thumbnail 

The regular Plotly graph displays fine

Also, trying to execute the python code via .p.e does not show an image, but just a thumbnail

.p.e["import plotly.express as px"]

.p.e["from IPython.display import Image, display"]

.p.e["fig=px.scatter(x=range(10), y=range(10))"]

.p.e["Image(fig.to_image(format='png'))"]

.p.e["display(Image(fig.to_image(format='png')))"]

1 Answer

0 votes
by (36.8k points)
edited by

The issue appears to be in the .qpk.mc function. Two ways to fix this, provided by a co-worker:

Either overriding a offending function

.qpk.mc:{y}

Inject into the html that can handle a encoded string

ipd[`:display]ipd[`:HTML]["<img src=\"data:image/png;base64,",.b64.enc[img`],"\">"];

Learn Python for Data Science Course to improve your technical knowledge.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...