joouha / euporie

Jupyter notebooks in the terminal
https://euporie.readthedocs.io
MIT License
1.54k stars 36 forks source link

Feature request: Plotly support #87

Closed fecet closed 11 months ago

fecet commented 11 months ago

It seems that euprie dosn't support plotly currenly, I test it by

import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.show()
joouha commented 11 months ago

Ploty renders charts as interactive SVG / HTML / Javascript, which euporie's HTML renderer is not yet capable of displaying.

You can convert your figure to an PNG image (you need kaleido installed for this), then use IPython to display the png in euporie:

%pip install --user kaleido

from IPython.display import Image
import plotly.express as px

fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])

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

image

It would be nice if plotly defined a _repr_png_ method, and returned png data as part of the _repr_mimebundle_ - I'll make a PR for this.

joouha commented 11 months ago

Even better, you can set the default plotly renderer to "png" and figures will be displayed as images!

import plotly.io as pio

pio.renderers.default = "png"

image

joouha commented 11 months ago

Have a read of this page:

https://plotly.com/python/renderers/

fecet commented 11 months ago

Thanks for your prompt response! Have some method to see the result in euprie would be good enough, does euporie plan to support interactive html in the future?

joouha commented 11 months ago

Have some method to see the result in euprie would be good enough, does euporie plan to support interactive html in the future?

As I said, you just need to pip install kaleido, and run:

import plotly.io as pio
pio.renderers.default = "png"

in your notebook to get plotly charts to display as static images.

Realistically, I'm not going to be implementing Javascript in euporie's webview any time soon.