[英]Plotly add trace comparative
如何在散点图中添加一条比较线,并保留 x 轴的轨迹。 在第一行中,它代表 x 轴上显示的范围,但第二行是前 30 天,但即使没有范围也显示出来
这是我的图表和我的代码,目前有另一行,但在不同的范围内,这就是为什么它不显示
fig = px.scatter(df_grouped, x=x, y=y, template=layout, height=200, width=530, color_discrete_sequence=palette)
fig.add_trace(go.Scatter(x=df_grouped[x], y=df_grouped[y], mode='lines'))
fig.add_trace(go.Scatter(x=df_grouped[x], y=df_grouped_last[y], mode='lines'))
df = pd.DataFrame(
{
"date": pd.date_range("5-sep-2021", freq="W", periods=8),
"line1": np.random.uniform(20, 30, 8),
"line2": np.random.uniform(20, 30, 8),
}
)
# prep dataframe to bring previous month aligned with current month
dfp = pd.merge(df, df, left_on="date", right_on=df["date"] + pd.Timedelta("28D"), suffixes=(" current", " previous"))
# plot current month and add previous month with additional hover info
px.line(dfp, x="date", y=["line1 current", "line2 current"]).add_traces(
px.line(dfp, x="date", y=["line1 previous", "line2 previous"], hover_data=["date previous"]).data
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.