简体   繁体   中英

I created a plot with plotly on a Jupyter Notebook but when I download it as an html file, the plot appears blank, what should I do?

I used plotly to create an interactive timeline of my data on a Jupyter Notebook. The plot on the notebook looks perfect and works just fine, however, when I download the notebook as an html file, I can't see the plot.

I will not share the original data frame for privacy reasons and because it isn't really relevant.

Here's the code I used to make the graph:

#Interactive Line Plot
import plotly 
import plotly.graph_objects as go

#Create figure
fig = go.Figure()

fig.add_trace(
    go.Scatter(x=list(df.Date), y=list(df.Transactions), marker=dict(size=20, color="blue")))

#Set title
fig.update_layout(title_text="Total Number of Transactions per Date", title_font_size=20)

#Add range slider
fig.update_layout(
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label="1m",
                     step="month",
                     stepmode="backward"),
                dict(count=6,
                     label="6m",
                     step="month",
                     stepmode="backward"),
                dict(count=1,
                     label="YTD",
                     step="year",
                     stepmode="todate"),
                dict(count=1,
                     label="1y",
                     step="year",
                     stepmode="backward"),
                dict(step="all")
            ])
        ),
        rangeslider=dict(
            visible=True
        ),
        type="date"
    )
)

fig.show()

In the Jupyter notebook I get a plot that looks like this:

Plot

But when I download the notebook as an html file the plot is blank, it doesn't appear. What should I do?

Thanks!

A bit late, but if you want plotly figures to be downloadable from Jupyter notebook, you do:

fig.show(renderer='notebook')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM