Always Have a Tick Mark At Top of Axis

Hi All,

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.

Hi @random1 ,

Welcome to the forum!

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()
    name='Primary Product',

# 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`
new_ymax = ymax+(ymax//3)

# 3. Update to y axes


Hope this help.

1 Like

This is pretty sweet actually, I will go for 1/5 above the current range because I think that fits nicely with most of my usecases

1 Like