Patch() extend with multiple traces

I’m using the new Patch() feature to extend my graphs on update instead of reloading each expensive graph. It’s not clear to me from the documentation how I can extend graphs with multiple traces. In the example below, I have a box plot that I can extend, however, I would like to extend the scatter plot as well, but I’m not certain how to specify which plot I’m extending. Thanks.

“”"

from dash import Dash, html, dcc, Input, Output, Patch
import plotly.graph_objects as go

app = Dash(name)

fig = go.Figure(
[
go.Box(x=[‘08:15’,‘08:15’,‘08:15’], y=[120,80,60]),
go.Scatter(x=[‘08:15’], y=[100]),
],
go.Layout(
dict(
annotations=[
dict(
x=‘08:15’,
y=130,
text=“95”,
showarrow=False,
),
]
),
showlegend=False,
),
)

app.layout = html.Div([
html.Button(“Show/Clear Annotations”, id=“clear-button”),
dcc.Graph(id=“clear-example”, figure=fig),
])

@app.callback(
Output(“clear-example”, “figure”),
Input(“clear-button”, “n_clicks”),
prevent_initial_call=True,
)
def add_data_to_fig(n_clicks):
patched_figure: object = Patch()
blood_pressure =[[120,80,60],[121,80,60],[122,80,60]]
triple_time = [[‘08:15’,‘08:15’,‘08:15’],[‘08:20’,‘08:20’,‘08:20’],[‘08:30’,‘08:30’,‘08:30’]]
hr = data_list[0]
for x in triple_time:
patched_figure[“data”][0][“x”].extend(x)
for y in blood_pressure:
patched_figure[“data”][0][“y”].extend(y)
return patched_figure

if name == “main”:
app.run_server(debug=True)
“”"

Hello @romarcin,

I think you need to build the list that you are pass and then pass the whole thing in list form:

patched_figure['data'][0]['x'].extend(new_x_list)
patched_figure['data'][0]['y'].extend(new_y_list)

Thank you for your reply. Apologies if I wasn’t clear. The above code successfully extends the bar graph, but I have an overlayed scatter plot. The below patch_figure does not specify which plot I wish to update; I can only update the bar graph currently. How do I specify a patch_figure for the scatter plot?

‘’’
patched_figure[‘data’][0][‘x’].extend(new_x_list)
patched_figure[‘data’][0][‘y’].extend(new_y_list)
‘’’

Assuming that it is on the second chart, you’d pass 1 instead of 0 in the above.