Contour hoverinfo not formatted correctly

Hi, I’m making a contour plot and have successfully changed the colorbar suffix and tick format. Changing these values for the xaxis and yaxis also changes the appearance in the hoverinfo. Is there any special way to change the formatting of the “z” value in the hoverinfo?

Also: is it possible to format the x,y,z prefix in the hoverinfo? I would like to label those with the axis title instead.



Thanks for bringing this up.

You’re correct. The tickprefix and ticksuffix settings set in colorbar have no effect on the hover labels.

To answer your question, no, there is no special way to change the formatting of the z value in the hoverinfo unfortunately.

To work around the problem, you can specify fully custom hover text by setting the text attribute in your contour trace object together with hoverinfo: 'text+name'. Note that you’ll need to use <br> to have multiple lines in your hover labels.

Looking forward, I’m not convinced the tickprefix and ticksuffix settings set in colorbar should have an effect on the hover labels.

Consider the case where a contour trace which has no apparent colorscale (by setting showscale: false). Then to change the hover label formatting one would have to enter into the colorbar object to set the desired prefix and suffix even though the colorscale wouldn’t show on the graph.

Maybe we could add a trace attribute e.g. zhoversuffix for trace types with a color dimension.

Or maybe we could come up with templating language for hoverinfo e.g. in your example have it set to '{x}<br>{y}<br>-->{z}:%'

where '-->' is the prefix and '%' the suffix.

Hey etienne, thanks for replying!

I agree a templating language or attributes to edit the suffix and prefix would be nice.

I wasn’t able to get the hoverinfo: ‘text+name’ method working. Could you give an example of what to set the trace.text to?

The documentation says it’s an array of text elements associated which each z value. I created a sample array with the same length as the z data with all values set to “test”. I wasn’t able to get the hoverinfo to display anything with the trace.hoverinfo attribute to ‘text+name’

Thanks again!

text must be a 2D array in this case.