Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly in Spyder?

I’ve been learning how to use plotly in the Jupyter notebook but prefer working in Spyder. Where can I find resources on how to run Plotly from Spyder?

Hi @staticL,

I just got it up and running on spyder 3.0 using the following steps. (windows 10)

  1. Download plotly using pip usig command line (python -m pip install plotly) this requires downloading python 3.5 separately from Spyder as well. (so far I haven’t had any conflicts)
  2. In Spyder, goto->Tools ->PYTHONPATH Manager -> addPath -> insert path to Plotly library (mine was in python\python36-32\Lib\site-packages), then synchronize
  3. Restart Spyder
  4. test it out with import plotly.plotly \n import plotly.graph_objs as go in a new .py scrypt

Hope it works out for you.
Cheers

1 Like

I follow the process and spyder and anaconda stop working.

Hi all,

To use plotly.py from Spyder, here’s what I would recommend:

  1. Download and install the anaconda Python distribution: https://www.anaconda.com/download/
  2. Install both Spyder and plotly.py using conda.
$ conda install -c plotly plotly spyder
  1. Create plots from spyder using the plotly.plotly.plot (online) or plotly.offline.plot (offline) functions. Each of these will open the plots in your default web browser.
  2. If you want static image export support, install the plotly-orca and psutil packages (See https://github.com/plotly/plotly.py#static-image-export)
$ conda install -c plotly plotly-orca psutil

-Jon

1 Like

I am still unable to run suggested solution provided by “jmmease”.
Any help would be appreicated in showing step by step on how to get the graphs to run in Spyder Anaconda or have the graphs show in a browser by running the code in “spyder”
Thank you

Hi @nadersmn,

After you’ve installed the plotly package, try running this code from spyder

from plotly.offline import plot
import plotly.graph_objs as go

fig = go.Figure(data=[go.Bar(y=[1, 3, 2])])
plot(fig, auto_open=True)

This should open up a bar chart in a new tab of your default browser.
Hope that helps!
-Jon

3 Likes

Hello Jon,

I am using spyder and I followed your instructions.
in my terminal
conda install -c plotly plotly spyder
conda install -c plotly plotly-orca psutil

I imported the graph objects as follows

from plotly.offline import plot
import plotly.graph_objs as go

I get the following error when I try this code

fig = go.Figure([go.Scatter(x=combined[‘Date’], y=combined[‘confirmed’])])

TypeError: super(type, obj): obj must be an instance or subtype of type

Do you have any suggestions?

Hi Jmmease, Using Anaconda - Spyder 4.0.0 on Windows 10,
It really helped. I didn’t redo the entire installation, just inserting this piece of code extra- as you’ve mentioned above.

plot(fig, auto_open=True)

really worked for me.