1
votes

I've created an offline plotly chart. I can't work out how to export it as an interactive HTML file. I can easily export the PNG version, but I'm after an interactive file.

Here is the chart I have generated.

And the code I used

import plotly as py
import plotly.graph_objs as go
import pandas as pd

py.offline.init_notebook_mode(connected=True)



df = pd.read_csv('C:/Users/Downloads/PopularPublisher.csv')
sd = df.nlargest(5,'Views')
fd = sd.sort_values(by='Views', ascending = True)


my_data = [go.Bar( x = fd.Views, y = fd.Publisher, orientation = 'h',)]
my_layout = go.Layout({"title": "Most popular publishers",
                       "yaxis": {"title":"Publisher"},
                       "xaxis": {"title":"Views"},
                       "showlegend": False}, yaxis=go.layout.YAxis(
        tickmode='array',
        automargin=True,
    )
    )


fig = go.Figure(data = my_data, layout = my_layout)

py.offline.iplot(fig)

I am appreciative for any guidance on how to export this file.

1

1 Answers

3
votes

You can change the last line of your code to py.offline.plot(fig, filename="file.html")

Or, if you've upgraded to version 4, you can use fig.write_html("file.html").