Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KeyError: 'plotly_domain' when using plotly to do scatter plot in python

I'm using plotly to do scatter plot. The graph is generated on my account but the terminal still reports an error:

Traceback (most recent call last):
File "IEORE4709HW1.py", line 106, in <module>
py.iplot(data, filename='basic-scatter')
File "/Library/Python/2.7/site-packages/plotly/plotly/plotly.py", line 175, in iplot
return tools.embed(url, **embed_options)
File "/Library/Python/2.7/site-packages/plotly/tools.py", line 412, in embed
!= session.get_session_config()['plotly_domain']):
KeyError: 'plotly_domain'

My code is:

import urllib2
import numpy as np

import plotly.plotly as py
py.sign_in('halblooline', 'j90503v8gq')
import plotly.graph_objs as go
import numpy as np

N = 1000
random_x = np.random.randn(N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook!
py.iplot(data, filename='basic-scatter')

# or plot with: plot_url = py.plot(data, filename='basic-line')

Any one could help me with this? Thank you very much.

like image 507
Jorvey Avatar asked Jan 21 '16 16:01

Jorvey


People also ask

How do you plotly plot in Python?

Plotly is a platform that runs on JSON, a format in which parameters are passed to the plotly API in dictionary formats. 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 .

What does Add_trace do in plotly?

Adding Traces New traces can be added to a plot_ly figure using the add_trace() method. This method accepts a plot_ly figure trace and adds it to the figure. This allows you to start with an empty figure, and add traces to it sequentially.

What is plotly Graph_objs?

The plotly.graph_objs module is the most important module that contains all of the class definitions for the objects that make up the plots you see.


1 Answers

use py.plot instead of py.iplot. Have a try.

like image 126
Ben Tan Avatar answered Oct 17 '22 08:10

Ben Tan