Cufflinks for plotly: setting cufflinks config options launches

前端 未结 5 1659
太阳男子
太阳男子 2021-01-05 06:02

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,

相关标签:
5条回答
  • 2021-01-05 06:24
    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)      
    
    0 讨论(0)
  • 2021-01-05 06:25

    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")
    
    0 讨论(0)
  • 2021-01-05 06:27

    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)
    
    0 讨论(0)
  • 2021-01-05 06:27

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

    0 讨论(0)
  • 2021-01-05 06:30

    just use this:

    import cufflinks as cf
    
    cf.set_config_file(offline=True)
    

    0 讨论(0)
提交回复
热议问题