我正在使用Dash绘制一个数据集,其中包含 x、y 列和水果类型的另一列。我在清单中添加了苹果和葡萄。我现在想要做的是让图表显示葡萄的 x 和 y 值,如果葡萄复选框被勾选,苹果如果苹果复选框被勾选,如果两者都被勾选。
有人可以帮助我吗?这是我知道的一个非常简单的问题。
我知道我需要以某种方式更改“def ... return”部分。
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
app = dash.Dash()
fruits = {'Day':[1,2,3,4,5,6],
'Visitors':[43,34,65,56,29,76],
'Bounce_Rate':[65,67,78,65,45,52],
'Nice_Fruits':['apple', 'apple', 'grape', 'apple', 'grape', 'grape']}
df_all_fruits = pd.DataFrame(fruits)
Nice_Fruits_list=df_all_fruits['Nice_Fruits'].unique()
app.layout = html.Div(children=[
html.H1('Payment Curve and predictor'),
html.Label('fruits_1'),
dcc.Checklist(
id='fruits_checklist',
options=[{'label': i, 'value': i} for i in Nice_Fruits_list],
values=['apple', 'grape'],
labelStyle={'display': 'inline-block'}
),
dcc.Graph(
id='fruits_graph',
figure={
'data': [
go.Scatter(
x=df_all_fruits['Visitors'],
y=df_all_fruits['Bounce_Rate'],
mode='markers',
opacity=0.7,
marker={
'size': 15,
'line': {'width': 0.5, 'color': 'white'}
},
)
],
'layout': go.Layout(
xaxis={'type': 'linear', 'title': 'Visitors'},
yaxis={'title': 'Bounce_Rate'},
margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
hovermode='closest'
)
}
),
])
慕丝7291255
相关分类