我已经创建了以下 plotly plotly 是这样的:
import plotly
labels = ['Oxygen', 'Hydrogen', 'Carbon_Dioxide', 'Nitrogen']
values = [4500, 2500, 1053, 500]
trace = plotly.graph_objs.Pie(labels=labels, values=values)
plotly.offline.plot([trace], filename='basic-pie-chart')
然后我创建了这样的html:
print(plotly.offline.plot([trace], include_plotlyjs=False, output_type='div'))
运行上面的代码会生成一个 .html 文件,我可以在浏览器中查看该文件。
有没有办法在我的 GitHub 页面上的 Markdown 文件中间显示 .html 文件,以便我可以使用 plotly 的交互功能?
Here is a similar question that I asked
最佳答案
如果您使用 Jekyll在您的 GitHub 页面站点中。
准备数据:
import plotly.graph_objects as go
labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500, 2500, 1053, 500]
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.show()
生成 HTML 文件:
import plotly.io as pio
pio.write_html(fig, file='figure.html', auto_open=True)
上传
figure.html
文件并将其提交到 _includes
站点存储库根目录中的文件夹。现在,如果您正在使用 markdown要创建您的帖子,您可以使用 include标记和调用
figure.html
在你的帖子里有这样的东西:{% include figure.html %}
将此行提交到您的帖子
.md
_posts
中的文件文件夹。检查结果。
关于python - 在 GitHub Pages 上显示交互式绘图图表(.html 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60513164/