Reputation: 121
Actually I am new in python.
When I am trying to compile the following code:
import matplotlib.pyplot as plt
import plotly.plotly as py
# Learn about API authentication here: https://plot.ly/python/getting-started
# Find your api_key here: https://plot.ly/settings/api
x = [1,2,3,4]
y = [3,4,8,6]
plt.plot(x, 'o')
plt.plot(y)
fig = plt.gcf()
plot_url = py.plot_mpl(fig, filename='mpl-line-scatter')
It shows the following message and don't give any output. :
mks@mks-H81M-S:~/Desktop/pythonPrograms$ python plot.py
Aw, snap! We don't have an account for ''. Want to try again? You can authenticate with your email address or username. Sign in is not case sensitive.
Don't have an account? plot.ly
Questions? [email protected]
xdg-open - opens a file or URL in the user's preferred application
Synopsis
xdg-open { file | URL }
xdg-open { --help | --manual | --version }
Use 'man xdg-open' or 'xdg-open --manual' for additional info.
mks@mks-H81M-S:~/Desktop/pythonPrograms$
I don't know what is this and how to fix it. Help.
Upvotes: 12
Views: 16274
Reputation: 769
Check the official documentation. What you are trying to do is online plotting of your graph using plotly cloud. That is the reason it is asking for authentication.
I ll suggest instead of logging in and trying to set an API Key, etc, it would be better if you do offline plotting.
The final plot gets saved as an HTML file in your local system which can be used later if needed. Here's how you do that:
import plotly as py
fig = dict( data=data, layout=layout )
py.offline.plot( fig, filename='d3-cloropleth-map' )
Upvotes: 3
Reputation: 131
I'm also pretty new as far as plotly on python is concerned. However, it seems to me that the problem is the fact that you are importing plotly.plotly.
To quote from the documentation
All methods in plotly.plotly will communicate with a Plotly Cloud or Plotly Enterprise. get_figure downloads a figure from plot.ly or Plotly Enterprise. You need to provide credentials to download figures: https://plot.ly/python/getting-started/
To the best of my understanding, you need to import plotly and then use functions as explained in the latter half of the introduction on this link Hope this helps
Upvotes: 13