Cufflinks for plotly: setting cufflinks config options launches

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


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)      

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

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)

Tags:

Python

Plotly