Python Plotly Facet Plot Y 轴标题更改

问题描述 投票:0回答:1

当我运行以下命令时:

df = px.data.tips()
fig = px.bar(df, x="sex", y="total_bill", color="smoker", barmode="group", facet_row="time", facet_col="day",
       category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
fig.update_layout(yaxis_title="Total Bill ($)")
fig.show()

我遇到的问题是,在我的绘图的 2 个 y 轴标题中,只有一个更改为“Total Bill ($)”,另一个保留为“total_bill”。

(https://i.stack.imgur.com/oUu0J.png)

有人知道怎么回事吗?

python plotly yaxis
1个回答
0
投票

非情节选项是

rename
该栏:

fig = px.bar(df.rename(columns={'total_bill': 'Total Bill ($)'}), 
             x="sex", y="Total Bill ($)", color="smoker", barmode="group", 
             facet_row="time", facet_col="day",
             category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], 
                              "time": ["Lunch", "Dinner"]})
fig.show()

输出:

© www.soinside.com 2019 - 2024. All rights reserved.