Plotly Express in Spyder (Offline Instead of iplot)

I love Spyder and it is my prefered environment

Plotly Express does not display in my Spyder Kernel, no matter my configuration. After some research, Plotly iplots function has already noted problems with using iplot, and the solution is to use Python offline. So my gyess is that Plotly Express exclusively uses iplot at the back. Is there a way I can use Plotly Express in Spyder? I use tools like seaborn for their direct integration in my analysis process, rather than D3, plotly, chart-studio, bokeh or bqplot. Perhaps if iplot is the issue, maybe a feature like writing, px.backend(‘offline’); could be used.

Thanks,
Oren

Hi @obahari,

Yes, Spyder is a great analysis environment! Right now, plotly_express returns a special go.Figure subclass that displays itself using plotly.offline.iplot when it’s asked to render itself in a Jupyter notebook context. If you’d like to display the figure in a browser, you can use plotly.offline.plot on the figure returned by plotly_express. Something like

import plotly_express as px
from plotly.offline import plot
fig = px.scatter(...)
plot(fig)

I’m also working on a brand new rendering subsystem for plotly.py that will become the default in version 4 that will make working in non-notebook contexts a lot easier. See https://github.com/plotly/plotly.py/pull/1474 for more details if you’re interested. And I’d appreciate help with testing if you’d be willing to give the development build a try.

To install, create a new virtual environment or conda environmnet and then run:

$ pip install https://11196-14579099-gh.circle-artifacts.com/0/dist/plotly-3.7.0%2B44.g2677dafe.tar.gz

Then check out the plotly.io.renderers section of https://github.com/plotly/plotly.py/pull/1474 for info on configuring renderers. For use in spyder, you’ll be most interested in the ‘browser’ renderer for displaying figures in a browser tab, and the ‘png’ renderer for displaying figures as static images inline in the QtConsole.

If you do give it a spin, please post any feeback on how it went as a comment on https://github.com/plotly/plotly.py/pull/1474. Thanks!

-Jon

1 Like

Hi,
I am getting the following error when running your suggested solution in spyder.

AttributeError: module ‘_plotly_utils’ has no attribute ‘basevalidators’

please help

Hi @nadersmn,

Often times this kind of error, where plotly can’t find it’s own modules, happens because there are somehow multiple versions of plotly.py installed.

Can you check the output of $ pip list and $ conda list to see if there are multiple versions of plotly installed?

-Jon