Plotly 在子图中更改 xaxis 的域

Plotly Changing the domain of xaxis in a subplot

我使用下面的代码绘制了两个子图。我想将 x 轴域/范围更改为与第一个子图相同的范围。换句话说,第一个子图的 x 值范围从 2004 年到 2010 年,而第二个轴的 x 值从 2010 年开始。我希望第二个子图也从 2004 年开始,然后一直到 2019 年。第二个子图的第一部分当然没有数据(2004 年到 2010 年),然后第二部分将具有相同的抛物线外观曲线(2010 年起) ).关于如何做到这一点的任何想法? .我在 plotly 中看到有一个选项可以更改域,但不确定如何为子图实现这一点。

Fig = make_subplots(rows = 2, cols = 1,subplot_titles = ['ndvi TS','anomaly'])
Fig.add_trace(go.Scatter(
    x = pd.to_datetime(df['ts'],format = '%d/%m/%Y'),
    y = df['fitted.values'],
    mode = 'lines',
    line = dict(
        color = 'steelblue',
        width = 2
    ),
    name = 'fitted line'
),
row = 1, col = 1
)

Fig.add_trace(go.Scatter(
    x = newdf['date'],
    y = newdf['cumulativeDelta'],
    mode = 'markers',
    marker = dict(
        color = 'lightcoral',
        size = 3,
        symbol = 'circle',
    ),
    name = 'Anomaly'
),
row = 2, col = 1
)

Fig.update_layout(
    width = 800,
    height = 600,
)

你应该为此使用 update_xaxes

fig.update_xaxes(range=["2004-01-21", "2020-03-23"])