Create Priorities for hovers on overlapping points

Hi. While creating a stacking area graph, I have encountered that if one of the areas has no value, it will have its marks overlapping the Scatter below. When there is hover information to be shown, it will only show the information of the one on top, which by definition is the one with value 0. As the hover text gives information about the values, the interesting one is the one which is not shown.

Ideally I would like to be able to determine which hover box has priority, instead of having the priorities determined by which are goes above which area.

Here is a MWE

fig = go.Figure()

fig.add_trace(
    go.Scatter(
        x=[1,2,3],
        y=[1,1,1],
        mode="lines+markers",
        stackgroup='stack',
        line={"shape":"hv","width":0.5},
        text="interesting info"
    )
)

fig.add_trace(
    go.Scatter(
        x=[1,2,3],
        y=[1,0,1],
        mode="lines+markers",
        stackgroup='stack',
        line={"shape":"hv","width":0.5},
        text="not so interesting info"
    )
)

fig.add_trace(
    go.Scatter(
        x=[1,2,3],
        y=[1,1,1],
        mode="lines+markers",
        stackgroup='stack',
        line={"shape":"hv","width":0.5},
        text="just some info"
    )
)
fig.show()

In this case I would like to be able to show the hover info of trace 0 instead of trace 1. Is there a way to explicitly determine the order of priority for hover boxes?

Thanks in advance!

P

Hi @pforero, welcome to the forum! I’m not aware of a way to set hover priorities (other than suppressing the hover altogether for a trace, with hoverinfo='skip'). However, you can change the hovermode with

fig.update_layout(hovermode='x')

so that the hover is displayed for all traces at a given value of x.