使用烧瓶离线绘图 [英] Plotly offline with flask

查看:22
本文介绍了使用烧瓶离线绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 flask 中离线使用 plotly .我知道 plotly 可以在 Ipython notebook 上离线使用,我可以在 flask 上离线使用 Plotly 吗?如果没有,有人可以建议我可以使用哪个python库在flask(离线库)中进行3D可视化

How can I use plotly offline with flask . I know that plotly can be used offline with Ipython notebook , Can I use Plotly offline with flask ? If not , can someone please suggest which python library can I use for 3 D visualisation in flask (offline library)

推荐答案

针对当前 Plotly 版本更新

Updated for current Plotly version

您要做的是制作返回离线情节"的函数.结果为 html <div>.为此,您使用 output_type=div" 调用 offline.plot() 方法.争论.这将返回一个纯字符串,然后您可以将其放入任何烧瓶模板中,它会显示图表!

What you want to do is make functions that return the offline "plot" result as a html <div>. To do this, you call the offline.plot() method with the output_type="div" argument. This will return a pure string that you can then put in any flask template, and it will show the graph!

此外,请确保在静态文件中包含 plotly.js 库,并在显示图形的 html 页面中链接到它们.

Also, make sure to include the plotly.js library in your static files and link to them in your html pages that show graphs.

这是我所说的一个例子:

This is an example of what I'm saying:

import plotly.graph_object as go
from plotly import io

fig = go.Figure(data=barChart, layout=barLayout)

div = io.to_html.plot(fig, show_link=False, output_type="div", include_plotlyjs=False)

return div

这篇关于使用烧瓶离线绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆