Black Lives Matter. Please consider donating to Black Girls Code today.

Hovertext for axis tick labels

I am adding custom text tick labels to my graph (using Figure.update_xaxes(ticktext=[...], tickvals=[...])). However some names are too long to be displayed in its entirety. I wish to truncate such names with an ellipsis, but allow the full name to be shown when a user hovers over the ticklabel.

To complicate things further the custom text are hyperlinks (through setting ticktext with html “<a href='...'>possibly long name</a>”) so the truncate/hover behavior should not interfere with being able to navigate the links.
My current solution is able to link and truncate, but lacks any hovertext. How should I add the hover elements (if possible)?

Thank you for any help :slight_smile:

Hi @pieterg did you take a look at Hover on Axis Tick Label? Since hovering on ticklabels is not supported, you can fake it either using the hover on points, with hovermode='x' (for example

import as px
fig = px.scatter(x=[1, 2], y=[1, 2], hover_data=[['loooong1', 'looooong2']])

), or you can add a second trace with invisible points at the location of tick labels.

Thanks for the suggestions! Unfortunate it’s going to be hacked in then. For the invisible trace suggestion, is it possible to have it right on the edge of the plot? I found this thread which suggests it’s not possible: Ignore certain traces from auto scale calculation is that the current state?