【问题标题】:Refreshing a matplolib plot on a flask app after updating dataset更新数据集后刷新烧瓶应用程序上的 matplotlib 图
【发布时间】:2020-12-29 15:57:02
【问题描述】:

我一直在使用这里的建议:

How to render and return plot to view in flask?

在我的烧瓶应用中创建一个绘图。

在应用程序中,我可以更新数据集中的实际值,并且绘图分别更新,但“上一条绘图线”没有。

我尝试将文件作为静态图保存在文件夹中,但更新后的数据没有刷新。

任何建议将不胜感激。

【问题讨论】:

  • 可能是在您的问题中添加代码后,我们找到了一些原因。您存储新图并表示该图的方法很好。
  • @Nour-AllahHussein 我正在使用链接中的代码。

标签: python matplotlib flask seaborn


【解决方案1】:

我刚刚找到了这个link,它为我的问题提供了解决方案。

基本上,改link in the question中的基本代码:

img = io.BytesIO() 
sns.set_style("dark")
plt.plot(df.Date, df.Value) 
plt.savefig(img, format='png', transparent = True) 
img.seek(0)   
plot_url = base64.b64encode(img.getvalue()).decode()

到:

fig,ax=plt.subplots(figsize=(6,6))
ax=sns.set(style="darkgrid")
sns.lineplot(df.Date, df.Value)
canvas=FigureCanvas(fig)
img = io.BytesIO()
fig.savefig(img,transparent = True)
img.seek(0)
plot_url = base64.b64encode(img.getvalue()).decode()

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 2022-09-28
    • 2022-10-13
    • 2019-07-05
    • 2021-06-05
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多