How to add 'hovermode' options to modebar?

Greetings,

This is a follow up question to the following post. I am adding more details in this question hoping it help to get an answer.

Even if Plotly cannot do it under certain circumstances, It helps me to know, so I won’t spend time to keep lookking for it.

Updated question with additional detail:

I learned that I can add some really useful options to Plotly’s modebar using a code like this:

import plotly.graph_objects as go
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x='petal_width', y='sepal_length', color='species')
fig.update_layout(
    dragmode='drawopenpath',
    newshape_line_color='cyan',
    title_text='Draw a path to separate versicolor and virginica',
    modebar_add=['drawline',
        'drawopenpath',
        'drawclosedpath',
        'drawcircle',
        'drawrect',
        'eraseshape'
       ]
)

However, still I am looking for options to add the hovermode options (like fig.update_layout(hovermode="x unified") ) to the modbar. On youtube I’ve seen people have the hovermode buttons on the modbar like the following screenshot:

image

How can I add buttons pointed above to my Plotly Python scatter charts?

Any help would be appreciated,

Hi @python-trader

The buttons you have highlighted can be added with:

fig.update_layout(
    modebar_add=[
        "v1hovermode",
        "toggleSpikeLines"
    ]
)

Hi @atharvakatre ,

That’s it! Thank you.

For the benefit of the community, and of the following code would conflict (or make it invisible) with ‘toggleSpikeLines’. It took me sometime to figure out the conflict:

fig.update_xaxes(showspikes=True, spikemode="across")
fig.update_yaxes(showspikes=True, spikemode="across")

 fig.update_layout(hovermode="x unified")
2 Likes