I get exactly the same issue in plotly v6.0.0.
Minimal working example:
import plotly.graph_objects as go
from plotly import data
from plotly.subplots import make_subplots
df = data.stocks()
fig = make_subplots(rows=2, cols=1, shared_xaxes=True)
fig.add_trace(go.Scatter(x=df["date"], y=df["AAPL"], name="A"), row=1, col=1)
fig.add_trace(go.Scatter(x=df["date"], y=df["GOOG"], name="B"), row=2, col=1)
fig.update_layout(hovermode="x unified") # allow hover (step 1)
fig.update_traces(xaxis="x1") # allow hover (step 2)
fig.for_each_xaxis(lambda x: x.update(showticklabels=True)) # tick labels are broken
fig.show()
Results:
Attempts at resolving the issue by manually defining a grid in fig.update_layout
(e.g.
this thread) does not work.
A workaround is to simply set fig.update_traces(xaxis="x2")
, or whatever the last row is, but that is a poor solution for very long charts with many subplots, where it is impossible to see the tick labels of the bottom-most plot. It will also not work for subplots with multiple columns.