Cufflinks for plotly: setting cufflinks config options launches

大城市里の小女人 提交于 2019-12-04 03:36:07
elsherbini

I think the issue is setting the filename argument in the iplot call.

df.iplot(kind='bar', barmode='stack')

http://nbviewer.jupyter.org/gist/santosjorge/5fdbe947496faf7af5e6

Edit if it is possible to do this with plotly, you can pass your cufflinks-generated figure to plotly.plot:

import cufflinks as cf
import plotly as py
fig = df.iplot(kind='bar', barmode='stack', asFigure=True)
py.offline.plot(fig)

This worked for me (assuming you have a folder name cufflinks):

import plotly.plotly as py
import plotly
import cufflinks as cf
import pandas as pd
import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, 
plot, iplot
init_notebook_mode(connected=True)
cf.go_offline()


# Offline html saving
df = pd.DataFrame(np.random.randn(1000, 3), columns=['A','B','C']).cumsum()
fig = df.iplot(asFigure=True)
plotly.offline.plot(fig,filename="cufflinks/example.html")

@elsherbini and @Charon: unfortunately I have not enough credentials to comment, so I have to write a new answer. your code pointed me into the right direction, but with the latest cufflinks version it goes even simpler:

import cufflinks as cf
df.iplot(kind='bar', barmode='stack', filename="my_barplot" , asPlot=True)

This code will generate a my_barplot.html file and open the plot in the default web browser. And this code is scriptable.

jfnewjfne
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from plotly import __version__
import plotly.graph_objs as go
import cufflinks as cf
from plotly.offline import download_plotlyjs,plot,iplot    

cf.go_offline()
df = pd.DataFrame(np.random.randn(100,4),columns = 'A B C D'.split())
print("\nHead for df : \n",df.head())

df2 = pd.DataFrame({'Category':['A','B','C'],'Values':[32,43,50]})
print("\ndf2 : \n",df2)

df.iplot(asPlot=True)      

just use this:

import cufflinks as cf

cf.set_config_file(offline=True)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!