在开发一个允许用户绘制特定数据的烧瓶网站时,我决定使用bokeh而不是matplotlib,因为它似乎是为嵌入而构建的,具有使用动态数据的能力。我已经浏览过网上的例子和bokeh文档。在示例中,我看到命令'create_ html _ snippet ',它应该返回可以插入到模板中的html片段:
from bokeh.plotting import *
import numpy as np
# Define a function that will return an HTML snippet.
def build_plot():
# Set the output for our plot.
output_file('plot.html', title='Plot')
# Create some data for our plot.
x_data = np.arange(1, 101)
y_data = np.random.randint(0, 101, 100)
# Create a line plot from our data.
line(x_data, y_data)
# Create an HTML snippet of our plot.
snippet = curplot().create_html_snippet(embed_base_url='../static/js/',
embed_save_loc='./static/js')
# Return the snippet we want to place in our page.
return snippet我与下面的主要烧瓶代码一起运行这段代码:
from flask import Flask, render_template
from plots import build_plot
app = Flask(__name__)
@app.route('/') # The base URL for the home page.
def render_plot():
plot_snippet = build_plot()
return plot_snippet
if __name__ == "__main__":
app.run(debug=True)在文档中找不到"create_html_snippet“命令,我的python的anaconda版本(由开发bokeh的人员创建)提供了以下错误:
AttributeError:“绘图”对象没有属性“create_html_snippet”
看起来bokeh正在经历快速的发展,我想知道它是否被废弃了。有人知道我正在寻找的html片段的最佳获取方式吗?
发布于 2014-06-27 04:55:41
create_html_snippet确实不受欢迎。我们将在7月7日发布Bokeh0.5,现在有一个改进、简化和文档化的bokeh.embed模块取代了这个功能。如果您想要更早地尝试,现在就有可以使用的dev构建,说明在邮件列表中有:
https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/NVxeqdYy2eQ
您可以在这里看到新的嵌入模块(包含完整的docstring):
https://github.com/ContinuumIO/bokeh/blob/master/bokeh/embed.py
以及一个非常好的水瓶嵌入示例如下:
https://github.com/ContinuumIO/bokeh/tree/master/examples/embed
我们还没有能力为dev构建发布Sphinx文档,但是您可以在这里查看新文档的标记文件:
这些内容也将得到更多的扩展,但它们现在给出了一个很好的概述。
编辑:说,暂时create_html_snippet应该还在,而且是功能性的。如果你想在GH上提出一个问题,我们可以讨论它或调查更多。
https://stackoverflow.com/questions/24444018
复制相似问题