如何使用 Plotly Express 显示 y 轴上的每个值?
How to show every value in y-axis using Plotly Express?
当我这样做时:
fig = px.line(df, x="day", y="avg_spending")
fig.show()
它不会以 2(0、2、4、...)为单位在 y 轴上放置值。我希望它是 1 x 1 (0,1,2,3,..)。我在 df 中“avg_spending”的最大值是 17,所以我希望 y 轴上有 1,2,3,...,17。怎么做?
在轴上设置dtick参数
import numpy as np
import pandas as pd
import plotly.express as px
df = pd.DataFrame({"day":range(50),"avg_spending":np.random.randint(1,17,50)})
fig = px.line(df, x="day", y="avg_spending")
fig.update_layout(yaxis={"dtick":1},margin={"t":0,"b":0},height=500)
当我这样做时:
fig = px.line(df, x="day", y="avg_spending")
fig.show()
它不会以 2(0、2、4、...)为单位在 y 轴上放置值。我希望它是 1 x 1 (0,1,2,3,..)。我在 df 中“avg_spending”的最大值是 17,所以我希望 y 轴上有 1,2,3,...,17。怎么做?
在轴上设置dtick参数
import numpy as np
import pandas as pd
import plotly.express as px
df = pd.DataFrame({"day":range(50),"avg_spending":np.random.randint(1,17,50)})
fig = px.line(df, x="day", y="avg_spending")
fig.update_layout(yaxis={"dtick":1},margin={"t":0,"b":0},height=500)