# Best method to add Trace to existing Figure

**URL:** https://community.plotly.com/t/best-method-to-add-trace-to-existing-figure/48059
**Category:** 📊 Plotly Python
**Created:** [December 10, 2020, 9:38am UTC](https://community.plotly.com/t/best-method-to-add-trace-to-existing-figure/48059 "2020-12-10T09:38:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ghtmtt](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/ghtmtt/32/51_2.png) [@ghtmtt](https://community.plotly.com/u/ghtmtt)
#### Post date: [December 10, 2020, 9:38am UTC](https://community.plotly.com/t/best-method-to-add-trace-to-existing-figure/48059/1 "2020-12-10T09:38:02Z")

</div>

Hi all,

what is the best _plotly_ way to add one or more Trace(s) to an existing Figure object using the output of plotly express? One scenario could be:

```auto
import plotly.express as px
import plotly.graph_objects as go

fig = go.Figure()
trace1= px.line(x=["a","b","c"], y=[1,3,2], title="first trace")
trace2 = px.line(x=["a","b","c"], y=[50,70,90], title="second trace")

fig.add_trace(trace1.data[0])
fig.add_trace(trace2.data[0])

fig.show()

```

then we can explicit add the type of plot to the figure (notice also the change from `title` to `name`)::

```auto

import plotly.express as px
import plotly.graph_objects as go

fig = px.line(x=["a","b","c"], y=[1,3,2], title="first trace")

fig.add_scatter(x=["a","b","c"], y=[50,70,90], name="second trace")

fig.show()

```

and another one _mixes_ plotly express and graph objects:

```auto
import plotly.express as px
import plotly.graph_objects as go

fig = px.line(x=["a","b","c"], y=[1,3,2], title="first trace")

fig.add_trace(go.Scatter(x=["a","b","c"], y=[50,70,90], name="second trace"))

fig.show()

```

I think all the methods are valid by I’m unsure what is the best one

Thanks to all!

Matteo

---

<div class="post-metadata">

### Author: ![Bijan](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bijan/32/22061_2.png) [@Bijan](https://community.plotly.com/u/Bijan)
#### Post date: [March 8, 2022, 10:06am UTC](https://community.plotly.com/t/best-method-to-add-trace-to-existing-figure/48059/2 "2022-03-08T10:06:10Z")

</div>

Dear Matteo @ghtmtt

Hi

Interesting topic and Useful!.

I had problem with adding a `px.line_3d` to the figure and I couldn’t add it using `fig.add_trace(go.line_3d)` because go doesn’t have `line_3d` and for some reasons I can’t use `go.Scatter3d` But your first scenario helped me 👍
