How to fix ugly tick spacing on line chart with small data set

Finally found the solution thanks to this post:

Adjusting Space Between Ticks.

Given data[“Year”] as a pd.Series of years in format YYYY, this gives evenly spaced x-axis ticks starting at the left edge and ending at the right edge of the fig.

fig.update_layout(
    xaxis=dict(
        tickvals=data["Year"],
        autorange=False,
        range=[0, len(data["Year"]) - 1],
        tick0=0,
        dtick=1
    ),
)

Small numbers of points on a scatter plot are never going to look great, but this is a pretty good solution imho.

1 Like