Cufflinks for plotly: setting cufflinks config options launches

▼魔方 西西 提交于 2019-11-30 04:22:01

问题


I'm trying to use cufflinks locally to generate plotly graphs from a pandas Dataframe

However, when I try and configure cufflinks in a python console, it then goes into ipython mode:

>>> import cufflinks as cf
>>> cf.set_config_file(offline=True)
In :

Subsequently, when I try and generate a plot, nothing appears:

In : df.iplot(kind='bar', barmode='stack', filename='cufflinks/test')
In : 

Can cufflinks be used offline without a plotly account?


回答1:


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)



回答2:


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")



回答3:


@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.




回答4:


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)      



回答5:


just use this:

import cufflinks as cf

cf.set_config_file(offline=True)



来源:https://stackoverflow.com/questions/35746074/cufflinks-for-plotly-setting-cufflinks-config-options-launches

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