Dean
Dean

Reputation: 171

Plotly: Figure window doesn't appear using Spyder

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()

Upvotes: 14

Views: 23890

Answers (4)

Relaxli
Relaxli

Reputation: 11

Regarding to working with kaleido, currently, there is an issue with version 0.2.1. Need downgrade to kaleido 0.1.*. See https://github.com/plotly/Kaleido/issues/110

Upvotes: 1

kurtusek
kurtusek

Reputation: 89

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()

Upvotes: 9

quantum_engineer
quantum_engineer

Reputation: 21

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.

Upvotes: 2

vestland
vestland

Reputation: 61084

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?

Upvotes: 22

Related Questions