# Plotly subplots using fig objects instead of traces

**URL:** <https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969>\
**Category:** 📊 Plotly Python\
**Created:** [July 20, 2018, 9:02pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969 "2018-07-20T21:02:15Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfernan](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@dfernan](https://community.plotly.com/u/dfernan)\
**Post date:** [July 20, 2018, 9:02pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/1 "2018-07-20T21:02:15Z")

</div>

Hi,

I have two plotly figures, one with two traces on a time series, and the other one is a scatter plot.

If I want to put them side by side, can I use subplots to do it? But I use the actual figure objects, not the individual traces.

---

<div class="post-metadata">

**Author:** ![bcd](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bcd](https://community.plotly.com/u/bcd)\
**Post date:** [July 23, 2018, 2:17am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/2 "2018-07-23T02:17:00Z")

</div>

Hey @dfernan

Have you seen Plotly’s subplot docs [https://plot.ly/python/subplots/](https://plot.ly/python/subplots/)

---

<div class="post-metadata">

**Author:** ![dfernan](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@dfernan](https://community.plotly.com/u/dfernan)\
**Post date:** [July 24, 2018, 2:44pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/3 "2018-07-24T14:44:53Z")

</div>

> [@bcd](#):
>
> Plotly’s subplot doc

Thanks.

Yes, it’s at the trace level, but no subplots can be done at the figure level.

I think generally it’s better to have better compartmentalization between the different figures. I’d want to create each figure separately, specially when working with very different figure types, each with it’s own complexities (legends, primary and secondary axis, etc.) and then the subplot by figure would be as easy as subfigs([fig1, fig2, fig3, fig4], rows=2, cols=2) or something like that. This would also allow for their own layouts, titles, etc. I think it has some advantages to it.

These are just suggestions, not sure how to do this yet.

I found this on the community forum so i guess it’s not really doable yet:

> [@Cant merge two figures into one big figure with sub figures, like subplots](https://community.plotly.com/t/cant-merge-two-figures-into-one-big-figure-with-sub-figures-like-subplots/6196):
>
> Hi, I have two customized figures which have multiple x axis and data sets. I am looking to add them to create one big figure with two sub figures , similar to sub plots. we do see subplots method, and append\_ trace method, however I could not find any append\_fig method. Can someone help here ? -Thx Jay

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [July 24, 2018, 8:37pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/4 "2018-07-24T20:37:43Z")

</div>

@dfernan  
With Plotly 3.0.0+ you can create what you call subplots of figures. Namely, you define the figures as instances of `go.FigureWidget()`.  
If you have two such figures, fw1, fw2, define

```auto
fig_subplots= HBox([fw1, fw2])
fig_subplots #this line displays the subplots in the Jupyter Notebook

```

 ![dashboard](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/dad7f09fddf32fec7c3ae822b5f07d93ec673e81.png)

To set the horizontal space between figures just update their margins:

```auto
fw1.layout.update(margin=dict( r=20))
fw2.layout.update(margin=dict( l=30))

```

If you have 3 or more figures you can locate them by a combination of `VBox` and `HBox`, imported from i`pywidgets`:

```auto
dashboard1=VBox([HBox([fw1, fw2]), HBox([fw3])])
dashboard1

```

 ![dasboard1](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/529d16de11a64ca103d6c77cd20a7ee9168fbd3e.png)

---

<div class="post-metadata">

**Author:** ![dfernan](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@dfernan](https://community.plotly.com/u/dfernan)\
**Post date:** [July 25, 2018, 5:48pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/5 "2018-07-25T17:48:31Z")

</div>

this is great, just updated my plotly version, important changes.

---

<div class="post-metadata">

**Author:** ![sergenyc1](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@sergenyc1](https://community.plotly.com/u/sergenyc1)\
**Post date:** [August 5, 2020, 1:00am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/7 "2020-08-05T01:00:45Z")

</div>

Hi I read through this post as I am trying to follow how to show multiple figures (“figs”). I am trying to show my multiple figs in a webpage via cmd.

I can “fig.show()” the individuals figs…

but then I try:

import plotly  
import plotly.graph\_objs as go  
import ipywidgets as ipw  
fig\_subplots - ipw.HBox([fig1, fig2])  
fig\_subplots.show()

I get an error that says:

AttributeError: ‘HBox’ object has no attribute ‘show’

how can I show the HBox in the webpage?

Can anyone help?

THANK YOU!

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [August 5, 2020, 6:40am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/8 "2020-08-05T06:40:41Z")

</div>

@sergenyc1

Unfortunately, figurewidgets can be displayed only in a Jupyter Notebook…

---

<div class="post-metadata">

**Author:** ![sergenyc1](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@sergenyc1](https://community.plotly.com/u/sergenyc1)\
**Post date:** [August 5, 2020, 2:41pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/9 "2020-08-05T14:41:58Z")

</div>

thank you very much for getting back to me. Is there another way with any Plotly tool to show multiple charts and tables in a webpage that you know of? Thank you very much again

---

<div class="post-metadata">

**Author:** ![tschlich](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/tschlich/32/23602_2.png) [@tschlich](https://community.plotly.com/u/tschlich)\
**Post date:** [August 24, 2020, 2:31am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/10 "2020-08-24T02:31:54Z")

</div>

Try Dash! You can put each graph object in its own HTML element.

---

<div class="post-metadata">

**Author:** ![Gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@Gaurav](https://community.plotly.com/u/Gaurav)\
**Post date:** [August 25, 2020, 6:57am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/11 "2020-08-25T06:57:24Z")

</div>

How to use categorical column in color in plotly graph objects ?

---

<div class="post-metadata">

**Author:** ![mohizzle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/mohizzle/32/14006_2.png) [@mohizzle](https://community.plotly.com/u/mohizzle)\
**Post date:** [March 25, 2021, 5:49pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/12 "2021-03-25T17:49:31Z")

</div>

> [@empet](#):
>
> go.FigureWidget()

Does this work in jupyterlab? I’m unable to get hbox to render in jupyterlab

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/f/fed3d3f1a99c97583d1ecaa4da7d925b041f1e6a.png)

if I try .show() I get ‘HBox’ object has no attribute ‘show’

---

<div class="post-metadata">

**Author:** ![mohizzle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/mohizzle/32/14006_2.png) [@mohizzle](https://community.plotly.com/u/mohizzle)\
**Post date:** [March 26, 2021, 10:46pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/13 "2021-03-26T22:46:00Z")

</div>

Looks like I was missing the Jupyterlab plotly plugins.

---

<div class="post-metadata">

**Author:** ![pjadzinsky](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@pjadzinsky](https://community.plotly.com/u/pjadzinsky)\
**Post date:** [June 15, 2021, 6:52pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/14 "2021-06-15T18:52:52Z")

</div>

Hi  
Any idea why these images don’t look the same size?

```auto
import ipywidgets as ipw
from plotly import express as px
import numpy as np
import plotly.graph_objects as go

fig = px.imshow(np.random.rand(3,3))
fig.update_layout(coloraxis_showscale=False)
fig.update_xaxes(showticklabels=False)
fig.update_yaxes(showticklabels=False)
fig = go.FigureWidget(fig)
ipw.HBox([fig, fig, fig])

```

 ![Screen Shot 2021-06-15 at 11.50.48 AM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/8/8a7c30927ca6a09b8cfa9300e09d653f4c1c9cd5.png)

---

<div class="post-metadata">

**Author:** ![z3h](https://avatars.discourse-cdn.com/v4/letter/z/4bbf92/32.png) [@z3h](https://community.plotly.com/u/z3h)\
**Post date:** [September 1, 2021, 12:29pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/15 "2021-09-01T12:29:56Z")

</div>

What is the problem with the following solution?

```python
from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=2, cols=1)

fig.add_trace(fig1.data[0], row=1, col=1)

fig.add_trace(fig2.data[0], row=2, col=1)

fig.update_layout(height=600, width=800, title_text="Panel layout")
fig.show()

```

---

<div class="post-metadata">

**Author:** ![aleskeyfedorovich](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@aleskeyfedorovich](https://community.plotly.com/u/aleskeyfedorovich)\
**Post date:** [August 25, 2023, 8:19am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/17 "2023-08-25T08:19:06Z")

</div>

that you are getting the traces of the original figures and not the whole figure

---

<div class="post-metadata">

**Author:** ![Madrigallo](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Madrigallo](https://community.plotly.com/u/Madrigallo)\
**Post date:** [September 4, 2023, 12:01pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/18 "2023-09-04T12:01:37Z")

</div>

It’s automatic rescaling because of window size, which does not treat all the elements within the HBox equally. You’ll need to set the box sizes firm not to see this I’d guess.

---

<div class="post-metadata">

**Author:** ![little\_raaaaay](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/little_raaaaay/32/25535_2.png) [@little\_raaaaay](https://community.plotly.com/u/little_raaaaay)\
**Post date:** [September 24, 2023, 11:34am UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/19 "2023-09-24T11:34:00Z")

</div>

@z3h another problem that I have is that, in my figures I have more than 1 line, so simply passing in `fig1.data[0]` isn’t enough because I want `fig1.data[1]` to be included as well, and passing in `fig1.data` gives and error which I don’t have to investigate right now but if anyone can educate me that would be great.

---

<div class="post-metadata">

**Author:** ![Tunneller](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@Tunneller](https://community.plotly.com/u/Tunneller)\
**Post date:** [October 5, 2023, 10:07pm UTC](https://community.plotly.com/t/plotly-subplots-using-fig-objects-instead-of-traces/11969/20 "2023-10-05T22:07:32Z")

</div>

Could you fork javascript into essentially two asynchronous executables and pass “fig1” to one executable and “fig2” to the other?
