Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 934
Dean Avatar asked Apr 07 '20 08:04

Dean


People also ask

How do you view plotly plots on Spyder?

Fix #1: Set the Default Renderer renderers. default. Once updated, you can run the fig. show() function and Plotly will display the figure as a static image in the Plots Tab in Spyder.

How do I open plotly in Python?

We can access this API in python using the plot.ly package. To install the package, open up terminal and type $ pip install plotly or $ sudo pip install plotly . Plotly's graphs are hosted using an online web service, so you'll first have to setup a free account online to store your plots.

How do you show plotly in Jupyter?

You can publish Jupyter Notebooks on Plotly. Simply visit plot.ly and select the + Create button in the upper right hand corner. Select Notebook and upload your Jupyter notebook (. ipynb) file!

How do you insert a plotly figure in HTML?

To share a plot from the Chart Studio Workspace, click 'Share' button on the left-hand side after saving the plot. The Share modal will pop-up and display a link under the 'Embed' tab. You can then copy and paste this link to your website. You have the option of embedding your plot as an HTML snippet or iframe.


2 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?

like image 51
vestland Avatar answered Oct 29 '22 01:10

vestland


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()
like image 27
kurtusek Avatar answered Oct 29 '22 00:10

kurtusek