I have this plot and I would like there to always be a tick mark at the top of the plot. i.e the range must move to 80 and there be a tickmark rather than just the bare line circled in red.
I want this to be dynamic for any plot making sure that there is always a tick mark just because it looks nicer. So if I have different input values it will always have a tick above the maximum range of the data.
This is just for static plotting btw so I have no need for it to maintain under zoom.
To add more tick above the maximum range of the data, you can use update y axis range.
But first you must find its maximum value and set the new maximum value.
For example you want to add like 1/3 from existing ranges
Which mean if your max value 60 then you add 20 ,new y axis range will be 80
import plotly.graph_objects as go
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
y=[40, 28, 60, 32, 36, 50, 38, 30, 24, 32, 28, 34]
fig = go.Figure()
fig.add_trace(go.Bar(
x=months,
y=y,
name='Primary Product',
marker_color='indianred'
))
# 1. Get the max of your range
ymax = max(y)
# 2. Get your new y axis range
# for example you want to add 1/3 from existing ranges
# you can play the value here, to get best `new_ymax`
print(ymax)
new_ymax = ymax+(ymax//3)
# 3. Update to y axes
fig.update_yaxes(range=(0,new_ymax))
fig.update_layout(xaxis_tickangle=-45)
fig.show()