我这里有一个示例代码,需要在这里添加水平线来显示平均线。在代码的哪一部分以及如何添加该行?也许我可以通过跟踪添加折线图?但是,我想不通。
我这里有一个很长的数据集,所以希望能举个例子。 在 Plotly 中添加形状在 Dash 中不起作用。
app = JupyterDash()
app.layout = html.Div([
html.H2("Building Population"),
html.Div(children='''Refresh for Total Estate Population.'''),
html.Div(
[
dcc.Dropdown(
id="Floor",
options=[{
'label': i,
'value': i
} for i in floor_options],
value='All Floors'),
],
style={'width': '25%',
'display': 'inline-block'}),
dcc.Graph(id='funnel-graph'),
])
@app.callback(
Output('funnel-graph', 'figure'),
[Input('Floor', 'value')])
def update_graph(Floor):
if Floor == "All Floors":
df_plot = total_population.copy()
else:
df_plot = total_population[total_population['Floor'] == Floor]
trace_desks_popl = go.Bar(
x=df_plot['Time Slot'],
y=df_plot['Occupancy x Hour x Floor'],
name='Desks',
marker_color = '#26A2ED'
)
trace_meeting_popl = go.Bar(
x=df_plot['Time Slot'],
y=df_plot['Population x Hour x Floor'],
name='Meeting Spaces',
marker_color = '#41C572'
)
return {
'data': [trace_desks_popl, trace_meeting_popl],
'layout':
go.Layout(
title='Total Population: {}'.format(Floor),
barmode='stack',
height=800)
}
if __name__ == '__main__':