Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Python line plot shows : Don't have an account? plot.ly

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.

like image 446
Textplus Avatar asked Mar 13 '17 18:03

Textplus


People also ask

Why Python is not showing plot?

It means if we are not using the show() function, it wouldn't show any plot. When we use the show() function in the non-interactive mode. That means when we write the code in the file it will show all the figures or plots and blocks until the plots have been closed.

How do you make a line plot in Python?

To create a line plot, pass an array or list of numbers as an argument to Matplotlib's plt. plot() function. The command plt. show() is needed at the end to show the plot.

Why is PLT plot blank?

The reason your plot is blank is that matplotlib didn't auto-adjust the axis according to the range of your patches. Usually, it will do the auto-adjust jobs with some main plot functions, such as plt. plot(), plt.

How do you add a title to a plot in Python?

In Matplotlib , we use the pyplot. title() method to give a title to a plot.


2 Answers

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' )
like image 62
Radioactive Avatar answered Sep 28 '22 19:09

Radioactive


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

like image 24
Cognitive Jester Avatar answered Sep 28 '22 21:09

Cognitive Jester