【发布时间】:2021-07-07 15:10:41
【问题描述】:
我想生成一个图并保存到内存中,然后将它作为变量传递给烧瓶,但我被卡住了。我已经编写了这段代码,它似乎可以在 google colab 中工作,当调用该函数时,它会生成绘图。但是我现在想将变量缓冲区传递给烧瓶渲染模板,但我完全卡住了
import io
def image_plot():
plt.figure()
my_ax = sns.violinplot(x=df_tweet["compound"])
plt.title('this is the twitter sentiment analysis for')
buffer = io.BytesIO()
my_ax.figure.savefig(buffer, format="png")
buffer.seek(0)
return buffer
return render_template("index.html", buffer=.....)
html 部分应该是...
<body>
<img id="picture" src="{{ buffer }}">
</body>
【问题讨论】: