Since I'm new to Flask, I hope someone can help me fix this problem. I am not able to show my plot in Flask and I don't know what is the problem. Here is my original code:
@app.route("/")
def index():
""" Returns html with the img tag for your plot.
"""
return f"""
<h1>Flask and matplotlib</h1>
<h3>Plot as a png</h3>
<img src="/variable.png"
alt="random points as png"
height="400"
>
"""
@app.route("/variable.png")
def plot_png():
""" renders the plot on the fly.
"""
fig=Figure()
with sns.axes_style(style='dark'):
g=sns.catplot("satisfaction", col="Gender", col_wrap=2, data=dft, kind="count", height=2.5, aspect=1.0,
palette='Set3')
plt.show(g)
output = io.BytesIO()
FigureCanvasAgg(fig).print_png(output)
return Response(output.getvalue(), mimetype="image/png")
Aucun commentaire:
Enregistrer un commentaire