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.
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.
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.
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.
In Matplotlib , we use the pyplot. title() method to give a title to a plot.
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' )
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With