# Combining or reusing subplot elements

**URL:** <https://discourse.julialang.org/t/combining-or-reusing-subplot-elements/96606>\
**Category:** Visualization\
**Tags:** plotting, controlsystems, layout-plots\
**Created:** [March 25, 2023, 8:05pm UTC](https://discourse.julialang.org/t/combining-or-reusing-subplot-elements/96606 "2023-03-25T20:05:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iabraham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iabraham/32/36532_2.png) [@iabraham](https://discourse.julialang.org/u/iabraham)\
**Post date:** [March 25, 2023, 8:05pm UTC](https://discourse.julialang.org/t/combining-or-reusing-subplot-elements/96606/1 "2023-03-25T20:05:53Z")

</div>

How can I extract and reuse/combine subplots in Julia? Consider:

```julia
pp = plot(0:0.01:2, [sin.(0:0.01:2), cos.(0:0.01:2)], layout=(1,2));
gg = plot(0:0.01:2, [sin.(0:0.01:2).^2, cos.(0:0.01:2).^2], layout=(1,2));

```

Both `pp` and `gg` report length 2 and are indexable, for example like: `pp[1]` and `gg[2]` etc.

```julia
julia> typeof(pp)
Plots.Plot{Plots.GRBackend}

julia> length(pp)
2

julia> pp[2]
Subplot{2}

```

How can I know extract and reuse these subplots? I tried:

```julia
mixed = plot(pp[1], gg[2], layout=(1,2))

```

expecting that Julia would know how to put Subplot objects into a new “plot container”; but no dice.

Of course I know I can make/do:

```julia
p1 = plot(0:0.01:2, sin.(0:0.01:2)
p2 = plot(0:0.01:2, cos.(0:0.01:2)
pp = plot(p1, p2, ...)

```

so I have re-usable pieces; but that is not my question.

**Use case:** Consider the output of [`bodeplot`](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/plotting/#ControlSystemsBase.bodeplot). If I have multiple transfer functions whose Bode plots I have already made and I want to reuse the magnitude plot from one system (`Subplot{1}` in the result) and the phase plot from _another_ system (`Subplot{2}` in the result) this would have been an easy way to do it.

**Note:** For the example use case mentioned above `ControlSystems.jl` does have a `plotphase=true` which can be supplied to the `bodeplot` call to just get the _magnitude_ plot. These can then be combined as appropriate. **However** , I don’t see a way to get just the phase plots. This post seems [related](https://discourse.julialang.org/t/plots-jl-combine-two-plots-into-one-with-two-series/4185) but that was posted 6 years back.
