# Patch() extend with multiple traces

**URL:** <https://community.plotly.com/t/patch-extend-with-multiple-traces/76536>\
**Category:** Dash Python\
**Created:** [June 30, 2023, 7:11pm UTC](https://community.plotly.com/t/patch-extend-with-multiple-traces/76536 "2023-06-30T19:11:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![romarcin](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@romarcin](https://community.plotly.com/u/romarcin)\
**Post date:** [June 30, 2023, 7:11pm UTC](https://community.plotly.com/t/patch-extend-with-multiple-traces/76536/1 "2023-06-30T19:11:53Z")

</div>

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)  
“”"

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [June 30, 2023, 7:30pm UTC](https://community.plotly.com/t/patch-extend-with-multiple-traces/76536/2 "2023-06-30T19:30:26Z")

</div>

Hello @romarcin,

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

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

```

---

<div class="post-metadata">

**Author:** ![romarcin](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@romarcin](https://community.plotly.com/u/romarcin)\
**Post date:** [June 30, 2023, 8:12pm UTC](https://community.plotly.com/t/patch-extend-with-multiple-traces/76536/3 "2023-06-30T20:12:42Z")

</div>

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)  
‘’’

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [June 30, 2023, 8:41pm UTC](https://community.plotly.com/t/patch-extend-with-multiple-traces/76536/4 "2023-06-30T20:41:43Z")

</div>

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