Thoughtfully inside jupyter notebook python

Does anyone know how to use plotly inside jupyter notebook using python?

The documentation is not very well organized, at least not from my point of view.

For example, I can run the following code, but it generates a graph in an HTML file, which can be accessed in OUTSIDE jupyter notebook . Is there a way for the graph to display inside the laptop?

What is also not clear to me (as the documentation leaves much to be desired) is that is credentials required to use plotly for graphs inside jupyter notebook ? Credentials are only needed to host plots in their cloud and nothing more?

I also found that there is no real cufflinks documentation. All he says makes it easy to use plotly with pandas dataframes. But for those who are not a developer, it would be nice if there were detailed documentation on why this is necessary and what exactly it does that makes life easier.

 import plotly.plotly as py from plotly.graph_objs import * trace0 = Scatter( x=[1, 2, 3, 4], y=[10, 15, 13, 17] ) trace1 = Scatter( x=[1, 2, 3, 4], y=[16, 5, 11, 9] ) data = Data([trace0, trace1]) plotly.offline.plot(data, filename = 'basic-line') /Users/blahblah/anaconda/lib/python2.7/site-packages/plotly/offline/offline.py:433: UserWarning: Your filename `basic-line` didn't end with .html. Adding .html to the end of your file. 'file:///Users/blahblach/Box Sync/NS/NBooks/basic-line.html' In [ ]: 

If I changed the last line in the code to:

 py.iplot(data, filename = 'basic-line') 

I get a credential error:

 PlotlyLocalCredentialsError: Couldn't find a 'username', 'api-key' pair for you on your local machine. To sign in temporarily (until you stop running Python), run: >>> import plotly.plotly as py >>> py.sign_in('username', 'api_key') Even better, save your credentials permanently using the 'tools' module: >>> import plotly.tools as tls >>> tls.set_credentials_file(username='username', api_key='api-key') For more help, see https://plot.ly/python. 

UPDATE:

I tried to execute pandas examples as described here .

I get validation errors for all df.iplot() or Series.iplot() .

Can someone explain why I get validation errors despite using iplot ().

There is also no useful documentation regarding cufflinks .

The plot.ly documentation is one of the worst I've seen. The organization is a mess and not very friendly for example.

+6
source share
2 answers

From docs you need to run Plotly Notebook with init_notebook_mode , also note that when py.iplot called py.iplot it still py.iplot the plot function from the plotly online module, you need to import iplot (without plot) from plotly.offline and use it for a stand-alone plot and laptop rendering. You do not need credentials for an offline schedule:

 from plotly.offline import init_notebook_mode, iplot from plotly.graph_objs import * init_notebook_mode(connected=True) # initiate notebook for offline plot trace0 = Scatter( x=[1, 2, 3, 4], y=[10, 15, 13, 17] ) trace1 = Scatter( x=[1, 2, 3, 4], y=[16, 5, 11, 9] ) data = Data([trace0, trace1]) iplot(data) # use plotly.offline.iplot for offline plot 

enter image description here

+5
source

Here is what worked for me. I use Anaconda, the plot is not decorated by Jupiter, but is generated from the outside, somehow it works.

 import plotly.offline as py import pandas as pd import plotly.graph_objs as go xl = pd.ExcelFile('c:\\Users\\xxx\Downloads\\krko.xlsx') df = xl.parse("All_Kr") krw=df.get_values()[:,12] # Column 13 kro=df.get_values()[:,11] # Column 12 Sw=df.get_values()[:,5] # Column 6 Sw_vs_krw=go.Scatter(x=Sw,y=krw,name='krw') Sw_vs_kro=go.Scatter(x=Sw,y=kro,name='kro') data = [Sw_vs_krw, Sw_vs_kro] py.plot(data,layout,filename='C:\\Users\\earro\\basic-line-plot.html') 

Tight decision

0
source

Source: https://habr.com/ru/post/1013506/


All Articles