Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: always show hovertext

Is there a parameter in Plotly (python) to make the hovertext boxes always show (i.e. rather than only when hovered over)?

The alternative is to make multiple annotations but I was hoping there might be a quicker solution.

like image 261
fishball Avatar asked Mar 27 '26 12:03

fishball


1 Answers

For a scatterplot I would create the 'text' attribute to the trace, then specify 'markers+lines+text' and a 'textposition'. This will plot some text next to every point that you specify. In the example below I've demonstrated that you can still use the <br> and <b> tags to style these labels. Obviously, depending on your data, you may need to position them a little more carefully.

import plotly
plotly.offline.init_notebook_mode()
trace = {'type' : 'scatter', 'x' : [1,2,3,4,5,6], 'y' : [1,2,3,4,5,6],
'text' : ['a<br>aaa','<b>b</b>','c','d','e','f'], 'mode' : 'markers+text', 
'textposition' : 'center right'}
plotly.offline.iplot([trace])

For a barplot or other, this will be a lot more difficult. You will probably have to go the annotation route, although you may get some mileage out of the PostMessage API, specifically the hover task (Plotly tutorial here).

Hope this helps!

like image 131
Rytchbass Avatar answered Mar 30 '26 01:03

Rytchbass



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!