-2

I have been using the suggestion here:

How to render and return plot to view in flask?

to create a plot in my flask app.

In the app I can update the actual values in the data set, and the plot updates respectively, BUT the 'previous plot line' does not. enter image description here

I tried saving the file as a static plot in a folder, but then the updated data is not refreshed.

Any suggestions will be appreciated.

Jorge
  • 2,181
  • 1
  • 19
  • 30

1 Answers1

0

I just found this link that offers a solution for my problem.

Basically, changing the basic code in the 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()

to:

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()
Jorge
  • 2,181
  • 1
  • 19
  • 30