问题描述
我有以下代码(在烧瓶视图中)显示不同餐厅在 12 个月内的平均评分:
@bp.route("/")
@bp.route("/index")
def index():
ratings = {
"restaurant_1": [3.6,3.2,4.1,3.9,4.6,4.4,5,4.8,4.2,3.7,4.3,3],"restaurant_2": [4.7,4,2.1,2.8,3.5,2,1],"restaurant_3": [3,1.1,1.5,1.7,3,1,1.8],"restaurant_4": [1,1.4,1.3,1.8]
}
basic_plot = px.line(
x=["January","February","march","April","May","June","July","August","September","October","November","December"],y=[ratings["restaurant_1"],ratings["restaurant_2"],ratings["restaurant_3"],ratings["restaurant_4"]],title="Brands rating",template="plotly_dark")
basic_plot.update_layout({
"title": "ratings evolution","xaxis_title": "Months","yaxis_title": "Average rating","legend_title": "Brands"
})
i = 0
for restaurant in ratings:
basic_plot["data"][i]["name"] = "Restaurant {}".format(i+1)
basic_plot["data"][i]["hovertemplate"] = "{}={}<br>{}=%{{x}}<br>{}=%{{y}}<extra></extra>".format(
"Month",basic_plot["data"][i]["name"],"Brand","Average rating"
)
i +=1
graph = basic_plot.to_html(full_html=False)
return render_template("index.html",graph=graph)
由于我将拥有更多餐厅,因此我想添加一个下拉过滤器,以便能够选择 1 家或更多餐厅(默认情况下仅选择 1 家)并根据选择。 这几个月也一样,因为我将获得更大的时间范围。
我找到了一些 Plotly 的例子,但没有找到 Plotly Express 的例子。 请注意,我使用的不是 Pandas,而是从 Psql 数据库加载的 Flask 模型的列表/字典。
感谢您的帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)