问题:需要把pandas的数据绘图并通过网页显示,matplotlib需要先保存图像,不合适。
解决:在网上搜了一下,找到一篇介绍文章 python可视化工具概述,其中介绍了几个python包,总结如下:
p = figure(title = code, plot_width=1024, plot_height=600, x_axis_type='datetime')
p.line(x=trd_df['date'], y=trd_df['close'])
script, div = components(p)
2、在flask中传递参数
return render_template('show_stock.html', bk_js = bokeh.resources.INLINE.render_js(), bk_css = bokeh.resources.INLINE.render_css(), p_script = script, div = p_div)
3、在html中调用显示
<!doctype html>
<html lang="en">
<head>
<meta charset='utf-8' />
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<title>Embed Demo</title>
{{ js_resources|indent(4)|safe }}
{{ css_resources|indent(4)|safe }}
{{ p_script|indent(4)|safe }}
</head>
<body>
{{ p_div|indent(4)|safe }}
</body>
</html>
更多功能,可以访问Bokeh官网:
http://bokeh.pydata.org/en/latest/index.html