12

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? support@plot.ly
 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.

Textplus
  • 121
  • 1
  • 1
  • 3
  • Possible duplicate of [Using plotly without online plotly account](http://stackoverflow.com/questions/37745917/using-plotly-without-online-plotly-account) – ImportanceOfBeingErnest Mar 13 '17 at 18:52
  • I have never used plotly online, so I can't help you much. Are you sure you have provided the username and api_key as strings? If this is your real api_key, I'm not sure if you should share it publically with everyone. – ImportanceOfBeingErnest Mar 13 '17 at 19:25
  • Thanks for this information. Would you help me please to set ofline setting – Textplus Mar 13 '17 at 19:29

2 Answers2

13

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

3

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' )
Jules Dupont
  • 7,259
  • 7
  • 39
  • 39
Radioactive
  • 611
  • 1
  • 11
  • 20