Plotly scatter: Change Interval length

Viewed 129

Need to change the Interval length of x axis from 10 to 7.

enter image description here

fig = px.scatter(df_2020_herb, 
                #  x = "ssn_start_utc",
                 x="PastTime", 
                 y="fld_id", 
                 color="Productname", 
                 hover_data=["name"], 
                 
                 )
fig.show()

I can't seem to find arguments to change it in the documentation. What should I do here

2 Answers

You can specify the xticks in the layout, and use a linear tickmode with the dtick set to 7. The documentation is here

fig.update_layout(
    xaxis = dict(
        tickmode = 'linear',
        tick0 = -60,
        dtick = 7
    )
)
df_2020_herb = pd.DataFrame({"PastTime":np.random.randint(-70,10,30),
                            "fld_id":np.random.randint(1,12,30),
                            "Productname":["Tillage"]*30}).assign(name=lambda d: d["Productname"])

fig = px.scatter(df_2020_herb, 
                #  x = "ssn_start_utc",
                 x="PastTime", 
                 y="fld_id", 
                 color="Productname", 
                 hover_data=["name"], 
                 
                 )

fig.update_layout(xaxis={"tickmode":"linear","dtick":7})

enter image description here

Related