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()
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.
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.
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!
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.
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:
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With