我正在尝试plotly.express
在 Flask 中显示条形图。但它是给予'Figure' object has no attribute savefig error
。使用时图像会正确显示fig.show()
。
import matplotlib.pyplot as plt
import plotly.express as px
figs = px.bar(
comp_df.head(10),
x = "Company",
y = "Staff",
title= "Top 10 departments",
color_discrete_sequence=["blue"],
height=500,
width=800
)
figs.savefig('static/images/staff_plot.png')
# fig.show()
return render_template('plot.html', name='new_plot', url='static/images/staff_plot.png')
在plot.html
中,图像显示如下:
<img src={{ url}} >