15

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()
5
  • My environment: The graph was displayed correctly in jupiter lab(mac), is it not a problem on the Spyder side? Commented Apr 7, 2020 at 9:11
  • @Dean Did my suggestion work out for you? Commented Apr 8, 2020 at 6:59
  • @vestland yep it did, thanks. Commented Apr 8, 2020 at 9:07
  • @quantum_engineer, I managed to get a static plot in Spyder too (by installing the dependencies and specifying 'iframe' as the renderer) Commented Apr 8, 2020 at 9:07
  • @Dean Would you consider marking one of the suggestions as the accepted answer? Commented Apr 14, 2020 at 6:20

4 Answers 4

24

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?

Sign up to request clarification or add additional context in comments.

Comments

9

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

2 Comments

*** As of plotly 4.9, orca has been deprecated and replaced by the kaleido library, which can be installed as pip install kaleido.
Had same issue. The orca solution worked fine for me. However have just spotted the comment re kaleido so I will investigate that also. Thanks all.....
2

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.

Comments

1

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

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.