Unified hovermode with sublots

Hi, I was wondering if is it possible to have the new unified hovermode working in the case we have subplots

from plotly.subplots import make_subplots
import plotly.graph_objs as go
import plotly.express as px

df = px.data.gapminder().query("continent=='Oceania'")

countries = df["country"].unique()

fig = make_subplots(rows=len(countries), cols=1, shared_xaxes=True)
for i,country in enumerate(countries):
    fig.add_trace(go.Scatter(x=df[df["country"]==country]["year"],
                             y=df[df["country"]==country]["lifeExp"],
                             name=country),

                      i+1,1)

fig.update_layout(hovermode="x unified")
fig.show()

Iโ€™ve an hovermode in every subplots but Iโ€™d like to have a straight line that go across subplots.

Hi @baobob, the โ€œx unifiedโ€ hovermode does not work (yet) across subplots. We have an open issue for this which you can subscribe to https://github.com/plotly/plotly.js/issues/4755. If youโ€™re only interested in the spike line extended to the other subplots you can do this with

fig.update_traces(xaxis='x1')

(imposing that there is only one xaxis)
but this will just give you the extended spike line, not the hover information of all subplots.

2 Likes

@Emmanuelle thanks. What Iโ€™d like to achieve is similar to Spain, confirmed weekly deaths plot in Economist

This works great! Thanks