【发布时间】:2017-04-05 06:53:12
【问题描述】:
以下sn-p代码生成matplotlib图并返回png:
@app.route('/plot/')
def test_image():
fig, ax = plt.subplots(1)
plt.plot(np.arange(100), np.random.normal(0, 1, 100))
canvas = FigureCanvas(fig)
img = BytesIO()
fig.savefig(img)
img.seek(0)
return send_file(img, mimetype='image/png')
在 html 中嵌入:
<img src="{{ url_for('test_image') }}" alt="Image Placeholder" height="300">
按预期工作。 但是,当尝试使用 jquery 更新图像时:
$.get('/plot', function(image){
$("#weapImage").html('<img src="data:image/png;base64,'+image+'" />')
})
【问题讨论】:
标签: python matplotlib flask