Search code examples
plotly

about Plotly (how can I post it for my github pages?)


I usually write files on ipynb, convert them into markdown files using nbconvert, and post them on my GitHub page. my theme is minimal-mistakes.

I want to post the contents of the data visualization using plotly recently, but when I converted it to Markdown on ipynb by nbconvert, there was no result unlike the graph of seaborne.

I have a few questions.

  1. Is the plotly graph not convertible when converting from ipynb to Markdown?
  2. How to include plotly's graph in the markdown and upload it on the git hub page

Solution

  • First, to use plotly graphs on the GitHub page, you must sign up for plotly and issue an api key.

    import plotly.express as px
    import chart_studio
    

    set your api

    chart_studio.tools.set_credentials_file(username=username, api_key=api_key)
    

    for example

    fig = px.line(data, x="", y="" ... )
    fig.show()
    
    url = chart_studio.plotly.plot(fig, filename="what u want", auto_open=False)
    chart_studio.tools.get_embed(url)
    

    If you write it as above, you can get a graph and an iframe url on ipynb, and it works good when I convert md by nbconvert

    I use it this way.

    import plotly.express as px
    import chart_studio as cs
    
    fig = px.line(df, x=, y=, title=)
    fig.show()
    
    cs.tools.get_embed(cs.plotly.plot(fig, filename="what u want", auto_open=False))