【发布时间】:2020-04-11 17:09:49
【问题描述】:
我正在尝试在 Flask 中显示 plotly.express 条形图。但它给了'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}} >
【问题讨论】:
标签: python-3.x flask plotly-python plotly-express