我没有一个很好的例子,所以我可以根据这个问题中的例子关闭滑块功能。(这个问题是如何使滑块对两个图表都有效。)我将第一个图表更改为 OHLC,第二个更改为音量。我没有来源或图表,所以这符合您的意图。第二个问题的意图不明确。
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.Ohlc(x=df['Date'],
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close']), row=1, col=1)
fig.add_trace(go.Bar(x=df['Date'], y=df['Volume']), 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=False
),
type="date"
)
)
fig.show()