plotly / plotly.py

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

Show only exact x matches in hover with hovermode="x unified" #4717

Open tlauli opened 1 month ago

tlauli commented 1 month ago

Currently, if there are two traces a, b with hovermode="x unified", then a value from trace b can be shown in the hoverinfo even when I am hovering on a x coordinate where there is no point in trace b, but only in trace a, see picture, where hovering over point from trace a with x=3 shows point from trace b with x=3.05. I would like a way to enforce that only points with exactly matching x coordinates are shown in the hover (something like hovermode="x unified exact"?).

image

Code to generate figure from the screenshot:

fig = go.Figure(
    layout=go.Layout(hovermode="x unified"),
    data=[
        go.Scatter(
            x=[1, 3],
            y=[1, 1],
            name="a",
        ),
        go.Scatter(
            x=[1, 3.05],
            y=[2, 2],
            name="b",
        ),
    ],
)