我正试图用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_title和yaxis_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"
)