Automatic font color

When I create a scatter plot, and specify to show hovertext by passing hovertext=my_text, hoverinfo='text' to Scatter, the hoverinfo box has the same background color as the marker it is attached to, and the font color is chosen automatically to have good contrast with the background in order to be readable. I love this feature!!

I would love to have this ability for other objects too, e.g. for the text of a marker itself, or general annotations. Is there something like color=automatic to achieve this?

Hi @vstauber,

Yeah, the auto-coloring of tooltip text is pretty cool :slightly_smiling_face:

I don’t of this feature being available elsewhere, but I like the sound of it. I think this would be a fine feature request for the Plotly.js project (this kind of change would need to flow through Plotly.js before making it to

In the meantime, if you compute the rgb color values yourself, you could use the color contrast formula from w3:


Hi @jmmease!

Thanks for the quick answer! I see, I will make a feature request there then :smiley:
Thanks also for the link, that formula is indeed helpful and can fix my issue for now, great!


1 Like