Adjusting space between ticks

I originally had a problem similar to this thread where the y-axis ticks would be very squished together. The suggestion was to set a pre-determined height.

However, my graph is of variable height. There could be anywhere from one to hundreds of points.

I start off with fig = go.Figure() and then add traces. Afterwards, I set the layout through something like this:

fig.update_layout(
        height=num_yaxis_ticks * 25 + 250, showlegend=False,
        yaxis=dict(tickmode='linear'), 
        xaxis=dict(side='top')
    )

I need all the yaxis ticks to be shown.

This works okay for most of the time, but the more y_axis ticks, the greater the space at the top and bottom of the graph. Here are some pictures for reference (yaxis tick labels cutoff for anonymity).

Here is a pretty normal looking graph with 4 yaxis ticks:

Here is a troublesome graph with at least 100 yaxis ticks (the bottom is cropped off) and a huge space at the top and bottom:

Any help is appreciated!

I had a similar problem with labeled ticks, iā€™m not sure if this will work for you.
What i did is to set the tick0 to 0, dtick to 1 and add a range.

fig.update_yaxes(
    autorage=False,
    range = [-1,len(df)],
    tick0=0,
    dtick=1
)