[Dash Bar chart] Customise axis unit font color by condition

Hi,

If you don’t mind manipulating the ticks array manually, you could use something like this:

midpoint = 262.5 # following your example
tickvals = [250, 255, 260, 265, 270, 275 280] # must be set manually

ticktext = [f"<span style='color: {'green' if t <= midpoint else 'red'}'>{t}</span>" for t in tickvals]

fig.update_yaxes(
   tickmode='array', 
   tickvals=tickvals,
   ticktext=ticktext, 
)

Wrapping the text in a HTML span element does the trick.

Otherwise, you could use two yaxis and have individual traces for bid and ask, but it gets much more complicated IMO.

Hope this helps! :smiley:

EDIT: Fixed undefined ticks.

2 Likes