# Plot a plot with subplot, given plots

**URL:** <https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [April 25, 2022, 7:55pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011 "2022-04-25T19:55:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 25, 2022, 7:55pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011/1 "2022-04-25T19:55:42Z")

</div>

I don’t know how to better describe this.

Given:

```julia
p1 = plot(rand(10))
p2 = plot(rand(10))

```

is there a way to use `p1` and `p2` to produce a two-subplot figure? Something like:

```julia
p = plot(layout=(2,1))
plot!(p, p1, subplot=1)
plot!(p, p2, subplot=2)

```

(that does not work, but the intention is clear, I think).

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 25, 2022, 8:02pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011/2 "2022-04-25T20:02:07Z")

</div>

[https://docs.juliaplots.org/stable/layouts/](https://docs.juliaplots.org/stable/layouts/)

Have to install it for a real example, and you know… TTFP 😉

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 25, 2022, 8:03pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011/3 "2022-04-25T20:03:58Z")

</div>

Oh, yes, I know how to do plots with multiple subplots. The thing here is that I had a function that returned a plot, and now I wanted to combine multiple returns of the function into a multiple-plot plot.

(but I have managed a workaround already, by passing the `Plot` structure to the function and the corresponding subplot).

Anyway I was curious if that could work.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 25, 2022, 8:04pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011/4 "2022-04-25T20:04:14Z")

</div>

```julia
plot(p1,p2,layout=(2,1))

```

well, my TTFP wasn’t that bad…  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/a/ea033f8ae66b4cbaf123bd03520b8f4cec84daec.png)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 25, 2022, 8:05pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011/5 "2022-04-25T20:05:45Z")

</div>

Isn’t that what you want?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 25, 2022, 8:06pm UTC](https://discourse.julialang.org/t/plot-a-plot-with-subplot-given-plots/80011/6 "2022-04-25T20:06:59Z")

</div>

Yes, great! didn’t realize that was possible.
