# Plotly express bar loses non-overlapping stack when moved into subplot

**URL:** <https://community.plotly.com/t/plotly-express-bar-loses-non-overlapping-stack-when-moved-into-subplot/65698>\
**Category:** 📊 Plotly Python\
**Created:** [July 2, 2022, 10:18am UTC](https://community.plotly.com/t/plotly-express-bar-loses-non-overlapping-stack-when-moved-into-subplot/65698 "2022-07-02T10:18:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marie](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/marie/32/19079_2.png) [@marie](https://community.plotly.com/u/marie)\
**Post date:** [July 2, 2022, 10:18am UTC](https://community.plotly.com/t/plotly-express-bar-loses-non-overlapping-stack-when-moved-into-subplot/65698/1 "2022-07-02T10:18:27Z")

</div>

I am creating a bar plot that shows relative contributions on a per row basis, such as this:

```auto
import pandas as pd
import plotly.express as px

d = pd.DataFrame({'a': [3,4,7], 'b': [5,4,1]})

fig = px.bar(d, x=d.index, y=['a','b'])
fig.show()

```

 ![pxbar](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/f/1/f1f172a5aa908d139901049b3b1408465555a5cb.png)

When I try to put this into a subplot by adding the plotly express traces, the bars are no longer stacked:

```auto
import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots

d = pd.DataFrame({'a': [3,4,7], 'b': [5,4,1]})

fig = px.bar(d, x=d.index, y=['a','b'])

fig2 = make_subplots(2,2)
fig2.add_traces(list(fig.select_traces()), rows=1, cols=1)
fig2.show()

```

 ![pxbar_addtraces](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/4/647c13d2acf0a8d9d039f2dce74532c6c762dd1d.png)

Any suggestions on how to reproduce the plotly express behavior within the subplot would be appreciated.

Thank you - Marie

---

<div class="post-metadata">

**Author:** ![marie](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/marie/32/19079_2.png) [@marie](https://community.plotly.com/u/marie)\
**Post date:** [July 5, 2022, 11:01am UTC](https://community.plotly.com/t/plotly-express-bar-loses-non-overlapping-stack-when-moved-into-subplot/65698/2 "2022-07-05T11:01:34Z")

</div>

The solution to this is to set the barmode of the subplot figure to relative:

```auto
fig2 = make_subplots(2,2)
fig2['layout'].barmode ='relative'
fig2.add_traces(list(fig.select_traces()), rows=1, cols=1)

fig2.show()

```

Best regards,  
Marie
