Plotly: Figure window doesn't appear using Spyder

Viewed 9568

I'm running the code below in Spyder 4.1.1 but the window that should contain the visualization doesn't appear. I am new to plotly. Please help.

import plotly.express as px
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()
3 Answers

To get you started quickly, you can set 'browser' as your renderer and launch your plotly figures in your default web browser. To my knowledge, this is the best way to produce plotly figures from Spyder and obtain the full flexibility of plotly figures (subsetting, zooming, etc).

Code:

import plotly.io as pio
import plotly.express as px
pio.renderers.default='browser'

fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()

Figure in browser:

enter image description here

For further details you could also check out the post Plotly: How to display charts in Spyder?

If you prefer to display in Spyder and not in your browser, you may need to install Orca. In your Anaconda terminal, use:

conda install -c plotly plotly-orca

From there, you should be able to use your previous code. Setting the default renderer explicitly could help, too:

import plotly.io as pio
import plotly.express as px
pio.renderers.default = "svg"

fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()

For plotly plots to appear in Spyder, a static image renderer is used. For that you need to have the required dependencies installed. This is detailed in the plotly renderer page.

Related