绘图轴标签不显示

plotly axis labels don't show

我正在尝试用 plotly bt 绘制一些东西,但轴标签没有显示。我找不到我做错了什么。

import plotly.graph_objects as go
df=pd.DataFrame({'month':[0,1,2,3],'counts1':[14,2,4,5], 'counts2':[19,3,4,1], 'counts3':[11,1,6,9]})

cols = df.drop(columns={'month'}).columns
fig = go.Figure()
for col in cols:
    fig.add_trace(go.Scatter(x=df['month'], y=df[col], mode='lines',
        name=col
    ))
fig.update_layout(scene = dict(
                    xaxis_title='X AXIS TITLE',
                    yaxis_title='Y AXIS TITLE'),
                    width=1000
                    )

fig.show()

你只需要设置xaxis_titleyaxis_title

import plotly.graph_objects as go

df = pd.DataFrame(
    {
        "month": [0, 1, 2, 3],
        "counts1": [14, 2, 4, 5],
        "counts2": [19, 3, 4, 1],
        "counts3": [11, 1, 6, 9],
    }
)

cols = df.drop(columns={"month"}).columns
fig = go.Figure()
for col in cols:
    fig.add_trace(go.Scatter(x=df["month"], y=df[col], mode="lines", name=col))
fig.update_layout(xaxis_title="X AXIS TITLE", yaxis_title="Y AXIS TITLE", width=1000)


fig.show()

使用Plotly Express

px.line(df, x="month", y=[c for c in df.columns if c != "month"]).update_layout(
    xaxis_title="X AXIS TITLE", yaxis_title="Y AXIS TITLE"
)