I am trying to plot something with plotly bt the axis labels don’t show. I can’t find what I’m doing wrong.
JavaScript
x
17
17
1
import plotly.graph_objects as go
2
df=pd.DataFrame({'month':[0,1,2,3],'counts1':[14,2,4,5], 'counts2':[19,3,4,1], 'counts3':[11,1,6,9]})
3
4
cols = df.drop(columns={'month'}).columns
5
fig = go.Figure()
6
for col in cols:
7
fig.add_trace(go.Scatter(x=df['month'], y=df[col], mode='lines',
8
name=col
9
))
10
fig.update_layout(scene = dict(
11
xaxis_title='X AXIS TITLE',
12
yaxis_title='Y AXIS TITLE'),
13
width=1000
14
)
15
16
fig.show()
17
Advertisement
Answer
You just need to set xaxis_title and yaxis_title
JavaScript
1
20
20
1
import plotly.graph_objects as go
2
3
df = pd.DataFrame(
4
{
5
"month": [0, 1, 2, 3],
6
"counts1": [14, 2, 4, 5],
7
"counts2": [19, 3, 4, 1],
8
"counts3": [11, 1, 6, 9],
9
}
10
)
11
12
cols = df.drop(columns={"month"}).columns
13
fig = go.Figure()
14
for col in cols:
15
fig.add_trace(go.Scatter(x=df["month"], y=df[col], mode="lines", name=col))
16
fig.update_layout(xaxis_title="X AXIS TITLE", yaxis_title="Y AXIS TITLE", width=1000)
17
18
19
fig.show()
20
Using Plotly Express
JavaScript
1
4
1
px.line(df, x="month", y=[c for c in df.columns if c != "month"]).update_layout(
2
xaxis_title="X AXIS TITLE", yaxis_title="Y AXIS TITLE"
3
)
4