我正在比较两个不同的数据集,我需要添加一个辅助y轴才能看到第二个数据集。 FX2(第一组)的Y值以指数形式大于BLX1(第二组)。两组都包含相同的“ G”列值,并且小部件应能够根据“ G”列绘制两组图形(也请检查一下)
这是我的代码:
month = widgets.IntSlider(
value=1.0,
min=1.0,
max=12.0,
step=1.0,
description='Month:',
continuous_update=False
)
use_date = widgets.Checkbox(
description='Date: ',
value=True,
)
container = widgets.HBox(children=[use_date, month])
textbox = widgets.Dropdown(
description='Client FX: ',
value= "123456 " ,
options=fx2['G'].unique().tolist(),
)
origin = widgets.Dropdown(
options=list(blx1['G'].unique()),
value="123456 " ,
description='ClientBalance:',
)
# Assign an empty figure widget with two traces
trace1 = go.Scattergl(x=fx2.index, y=fx2['buy_flow'], opacity=0.75, name='FX', mode= 'markers', secondary_y=True)
trace2 = go.Histogram(x=blx1.index, y=blx1['bal'], opacity=0.75, name='Balance')
g = go.FigureWidget(data=[trace1, trace2],
layout=go.Layout(
title=dict(
text='Client Analysis'
),
barmode='overlay'
))
def validate():
if origin.value in blx1['G'].unique() and textbox.value in fx2['G'].unique():
return True
else:
return False
def response(change):
if validate():
if use_date.value:
filter_list = [i and j and k for i, j, k in
zip(fx2.index == month.value, fx2.index == textbox.value,
blx1.index == origin.value)]
temp_df = df[filter_list]
else:
filter_list = [i and j for i, j in
zip( fx2['G'] == "123456" , blx1['G'] == "123456")]
temp_df = df[filter_list]
x1 = temp_df['arr_delay']
x2 = temp_df['dep_delay']
with g.batch_update():
g.data[0].x = x1
g.data[1].x = x2
g.layout.barmode = 'overlay'
g.layout.xaxis.title = 'Date'
g.layout.yaxis.title = 'Value'
origin.observe(response, names="value")
textbox.observe(response, names="value")
month.observe(response, names="value")
use_date.observe(response, names="value")
def validate():
if origin.value in blx1['G'].unique() and textbox.value in fx2['G'].unique():
return True
else:
return False
def response(change):
if validate():
if use_date.value:
filter_list = [i and j and k for i, j, k in
zip(fx2.index == month.value, fx2.index == textbox.value,
blx1.index == origin.value)]
temp_df = df[filter_list]
else:
filter_list = [i and j for i, j in
zip( fx2['G'] == 123456 , blx1['G'] == 123456)]
temp_df = df[filter_list]
x1 = temp_df['arr_delay']
x2 = temp_df['dep_delay']
with g.batch_update():
g.data[0].x = x1
g.data[1].x = x2
g.layout.barmode = 'overlay'
g.layout.xaxis.title = 'Date'
g.layout.yaxis.title = 'Values'
origin.observe(response, names="value")
textbox.observe(response, names="value")
month.observe(response, names="value")
use_date.observe(response, names="value")
container2 = widgets.HBox([origin, textbox])
widgets.VBox([container,
container2,
g])