简体   繁体   English

单个 slider 用于多个 plotly 子图

[英]Single slider for multiple plotly subplots

import pandas as pd
import plotly.graph_objs as go
from plotly.subplots import make_subplots

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")

df.columns = [col.replace("AAPL.", "") for col in df.columns]

fig = make_subplots(1, 2)

fig.add_trace(
    go.Scatter(x=list(df.Date), y=list(df.High)), row=1, col=1)

fig.add_trace(
    go.Scatter(x=list(df.Date), y=list(df.Low)), row=1, col=2)


fig.update_layout(
    xaxis=dict(
    rangeselector=dict(
        buttons=list([
            dict(count=1,
                 label="1m",
                 step="month",
                 stepmode="backward"),
            dict(count=6,
                 label="6m",
                 step="month",
                 stepmode="backward"),
            dict(count=1,
                 label="YTD",
                 step="year",
                 stepmode="todate"),
            dict(count=1,
                 label="1y",
                 step="year",
                 stepmode="backward"),
            dict(step="all")
        ])
    ),
    rangeslider=dict(
        visible=True
    ),
    type="date"
)
)


import plotly.offline as pyo
pyo.plot(fig)

I want to create one common slider for both of the plots.我想为这两个地块创建一个通用的 slider。 Currently there are two graphs but slider is working only for one of them.目前有两个图表,但 slider 仅适用于其中一个。 Is it possible to make the current slider common for all the multiple graphs in a subplot?是否有可能使当前 slider 对于子图中的所有多个图形都是通用的?

Add line below.在下面添加行。

fig.update_xaxes(matches='x')

first select the subplot you don't want the slider to apper, lets think it is the row=1 and col=1 subplot首先 select 您不希望 slider 出现的子图,假设它是 row=1 和 col=1 子图

then add the line然后添加行

fig.update_xaxes(row=1, col=1, rangeslider_visible=False)

then both of the charts will have only one slider那么两个图表都只有一个 slider

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM