# Convert plotly.express in to plotly.graph\_objects

**URL:** <https://community.plotly.com/t/convert-plotly-express-in-to-plotly-graph-objects/31656>\
**Category:** 📊 Plotly Python\
**Created:** [November 21, 2019, 11:32am UTC](https://community.plotly.com/t/convert-plotly-express-in-to-plotly-graph-objects/31656 "2019-11-21T11:32:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceuzebio](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@ceuzebio](https://community.plotly.com/u/ceuzebio)\
**Post date:** [November 21, 2019, 11:32am UTC](https://community.plotly.com/t/convert-plotly-express-in-to-plotly-graph-objects/31656/1 "2019-11-21T11:32:59Z")

</div>

Hi Guys,

I trying to replicate a cahr created in plotly.experss to plotly.graph\_objects but a failing in every times.  
I have this dataframe base.

```auto
Machine	Time	Units Pruduced
0	K2K01	2	579
1	K2K01	3	350
2	K2K01	4	848
3	K2K01	5	840
4	K2K01	15	768
5	K2K01	17	1752
6	K2K02	1	712
7	K2K02	2	804
8	K2K02	3	327...

```

And i build char in plotly.express.

```auto
fig = px.scatter(fdr4, x="Time", y="Units Pruduced", color="Machine", template="plotly_white")
fig.update_traces(mode='lines+markers')
fig.show()

```

This is the result.

 ![19](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/0/073bae19a76c565eb2ab30b470282a88d1c347b7.png)

Also i tryed build in plotly.graph\_objects.  
PS: This is the more closer i get from expected result.

```auto
figure = {
            'data' : [
                go.Scatter(
                
                x = fdr4.index,
                y = fdr4.UnitsProd,
                mode = "markers+lines",
                name = rowname
                )for rowname in fdr4.Machine

```

And this is the result.

 ![41](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/a47fa5d9332d8ac7917319f96ae9f3ee04a3476f.png)

So, could please someone advise me or give some reference what is incorrect in my logic with plotly.graph\_objects that graph to generate the same chart as plotly.experss with the same datas?

Thank you.

---

<div class="post-metadata">

**Author:** ![wbrgss](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/wbrgss/32/3621_2.png) [@wbrgss](https://community.plotly.com/u/wbrgss)\
**Post date:** [November 26, 2019, 5:35pm UTC](https://community.plotly.com/t/convert-plotly-express-in-to-plotly-graph-objects/31656/2 "2019-11-26T17:35:36Z")

</div>

With the `color` parameter, Plotly Express will group your data such that each “Machine” in your data has a separate “trace”, along with its own corresponding color in the default colorway.

Plotly Express simply does this grouping internally to generate a figure with the same syntax as `plotly.graph_objects`. In order to see the figure it generates, you can `print(fig)`, or

```auto
import pdb; pdb.set_trace()

```

and inspect the `fig` in the Pdb REPL. Then you can copy-and-paste the generated `'data'` list and `'figure'` dict into your `figure` dict that is supplied as an argument for `plotly.graph_objects`. The result should then be the same.

Also, FYI, a more appropriate category for this question is in the API \> Python category. In the future, you may get more attention on Plotly Express/Graph Objects-related Python questions if you use that category instead of “Dash”. I changed the category myself just now.
