# Using Layout properly for Multiple plots in same box

**URL:** <https://discourse.julialang.org/t/using-layout-properly-for-multiple-plots-in-same-box/109241>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [January 25, 2024, 8:56am UTC](https://discourse.julialang.org/t/using-layout-properly-for-multiple-plots-in-same-box/109241 "2024-01-25T08:56:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [January 25, 2024, 8:56am UTC](https://discourse.julialang.org/t/using-layout-properly-for-multiple-plots-in-same-box/109241/1 "2024-01-25T08:56:45Z")

</div>

Hi all, I’m trying to get 2 plots (one on top of the other) in the same box, using the `layout` command, but I can’t seem to get the syntax right without errors.

Julia’s document lists some examples using random numbers, such as:  
`plot(rand(100, 4), layout = (4, 1))`  
but, I have arrays of actual values to plot. So my current plotting command is something like:  
`plot(xArray1[1:end], yArray1[1:end], color="blue"); plot!(xArray2[1:end], yArray2[1:end], color="red")`

How to use `layout = (2,1)` the correct way to separate these plots and put them one on top of another? Thanks…!

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [February 2, 2024, 9:12pm UTC](https://discourse.julialang.org/t/using-layout-properly-for-multiple-plots-in-same-box/109241/2 "2024-02-02T21:12:01Z")

</div>

Hi again, any ideas for the correct syntax for this? Googling the `layout` command and trial-and-error haven’t helped so far. Thank you.

---

<div class="post-metadata">

**Author:** ![JulesJyu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/julesjyu/32/202991_2.png) [@JulesJyu](https://discourse.julialang.org/u/JulesJyu)\
**Post date:** [February 12, 2024, 4:29am UTC](https://discourse.julialang.org/t/using-layout-properly-for-multiple-plots-in-same-box/109241/3 "2024-02-12T04:29:36Z")

</div>

You can try to use below

```julia
using Plots

plt1 = plot(sin, 0:2\pi)
layout_setting = @layout [a;b;c d]
plot(plt1, plt1, plt1, plt1, layout = layout_setting)

```

you may find the macro layout provides what you want.

[a;b;c d] # the semicon ; separate the rows, and space sepearte the columns

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [February 13, 2024, 5:43pm UTC](https://discourse.julialang.org/t/using-layout-properly-for-multiple-plots-in-same-box/109241/4 "2024-02-13T17:43:59Z")

</div>

Hello JulesJyu, I have adapted your suggestion to my 2-plot attempt, and it works, thank you!

My final (working) code:

```julia
using Plots

xArray1 = rand(15); yArray1 = rand(15);
xArray2 = rand(15); yArray2 = rand(15);

plt1 = plot(xArray1, yArray1, color="blue");
plt2 = plot(xArray2, yArray2, color = "red");

layout_setting = @layout [a;b]
plot(plt1, plt2, layout = layout_setting)

```
