在一个允许用户绘制某些数据的烧瓶网站上工作时,我决定使用 bokeh 而不是 matplotlib,因为它似乎是为嵌入而构建的,并且能够使用动态数据。我搜索了在线示例和散景文档。在示例中,我看到命令“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(由开发散景的同一个人创建)给出以下错误:
AttributeError:“绘图”对象没有属性“create_html_snippet”
散景似乎正在快速发展,我想知道它是否已被弃用。有谁知道当前获取我正在寻找的 html 片段的最佳方法?