plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.09k stars 2.54k forks source link

allow aligning hovertext for annotations #3583

Open psmaragdis opened 2 years ago

psmaragdis commented 2 years ago

It looks like there is no way to control the text justification for annotation hovertexts. For example:

# Make an background image
f = px.imshow( [[255]*6]*3, origin='lower')

# Add two annotations with hovertext
f.add_annotation( x=1, y=1, text='left', hovertext='Will be left justified<br>*', showarrow=False)
f.add_annotation( x=5, y=1, text='right', hovertext='Will be right justified<br>*', showarrow=False)

# Tighten the plot
f.update_layout( margin={'l':0, 'r':0, 't':0, 'b':0}, coloraxis_showscale=False)

# This will not apply on the annotation hovertext
f.update_layout( hoverlabel_align='left') 

# This does not exist and annotation hovertexts default to auto
# f.update_annotations( hoverlabel_align='left')

f.show()

The image hovertexts will be all properly left-justified, but the annotation hovertexts will default to 'auto', with the left one being left-justified, and the right one being right-justified. Am I missing something, or this is an omission in the tunable options? Is there some other way to force left-justification on the annotation hovertexts? I produce a set of tables that way that look atrocious otherwise.

Thanks!

jvanhou commented 1 year ago

Am experiencing the same issue. Have you found a workaround for this? Thanks