# How to use @layout in plots?

**URL:** <https://discourse.julialang.org/t/how-to-use-layout-in-plots/53722>\
**Category:** Visualization\
**Tags:** plots, layout-plots\
**Created:** [January 21, 2021, 1:19pm UTC](https://discourse.julialang.org/t/how-to-use-layout-in-plots/53722 "2021-01-21T13:19:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [January 21, 2021, 1:19pm UTC](https://discourse.julialang.org/t/how-to-use-layout-in-plots/53722/1 "2021-01-21T13:19:48Z")

</div>

Hello,

I am trying to create layouts for subplots, which are not pure grids. However, I find very little instructions on this. What I have found is a small section in the docs ([Layouts · Plots](https://docs.juliaplots.org/latest/layouts/) which also contains a broken link to the Julia’s [multidimensional Array construction](https://docs.julialang.org/en/latest/manual/arrays/#man-array-concatenation-1) multidimensional array construction. I think I found what it is supposed to be pointing at, but it would be helpful to be sure). What was most useful might have been this very short discussion on the discourse: [Plots.jl @layout macro usage](https://discourse.julialang.org/t/plots-jl-layout-macro-usage/11024)

There is the macro for creating layouts, with and example:

```julia
l = @layout [
    a{0.3w} [grid(3,3)
             b{0.2h} ]
]
plot(
    rand(10, 11),
    layout = l, legend = false, seriestype = [:bar :scatter :path],
    title = ["($i)" for j in 1:1, i in 1:11], titleloc = :right, titlefont = font(8)
)

```

But say I want to remove either the plot on the bottom, or the top. It feels intuitive that I would simply do some version of

```julia
l = @layout [
             [grid(3,3)
             b{0.2h} ]
]

```

for removing the one on the left

or

```julia
l = @layout [
    a{0.3w} [grid(3,3)
               ]
]

```

for removing the one on the bottom. But both these yields errors.

Is there some more extensive instructions somewhere which I have missed, or is the documentations simply not complete?  
(or maybe most likely, is this the documentation for the macro, and I simply not able to understand it?)

Ideally, I would like to create something like a 3x3 grid of plots, and next to it a 1x4 of 4 plots (of identical width as the 3x3 plots, with the top and bottom plot at half the hight of the plots in the 3x3, and the two middle ones of identical height)

---

<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:** [January 21, 2021, 1:40pm UTC](https://discourse.julialang.org/t/how-to-use-layout-in-plots/53722/2 "2021-01-21T13:40:42Z")

</div>

If you find any better explanation of that, please post it here. I recently wanted to build a complex layout with plots, and got completely frustrated.

---

<div class="post-metadata">

**Author:** ![FPGro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fpgro/32/20822_2.png) [@FPGro](https://discourse.julialang.org/u/FPGro)\
**Post date:** [January 21, 2021, 8:10pm UTC](https://discourse.julialang.org/t/how-to-use-layout-in-plots/53722/3 "2021-01-21T20:10:17Z")

</div>

> [@Torkel](#):
>
> ```julia
> l = @layout [
> [grid(3,3)
> b{0.2h} ]
> ]
> 
> ```

the outer array now has only a single element, making it a vector, which is confusing to layouts because it expects things that make a matrix. You just just need to drop one pair of brackets for it to work:

```julia
l = @layout [grid(3,3)
             b{0.2h} ]

```

Similar with the other one, drop the unused brackets.  
What you want for your 4 in a row + 3 grid thing could be:

```julia
julia> l = @layout [[a{0.25h};b;c;d{0.25h}] grid(3,3)]
Plots.GridLayout(1, 2)

```

EDIT: Half of 1/4 is 0.125 not 0.25 ofc, that one’s on me. Here’s a working example:

```julia
julia> l = @layout [[a{0.125h};b;c;d{0.125h}] grid(3,3){0.66w}]
Plots.GridLayout(1, 2)

julia> plot(
           rand(10, 13),
           layout = l, legend = false, seriestype = [:bar :scatter :path],
           title = ["($i)" for j in 1:1, i in 1:13], titleloc = :right, titlefont = font(8)
           )

```

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [January 22, 2021, 12:12pm UTC](https://discourse.julialang.org/t/how-to-use-layout-in-plots/53722/4 "2021-01-22T12:12:40Z")

</div>

Thanks, that is really helpful! I managed to create the layout I wanted using your code. It also helped me understand how it worked better, so I managed to create some other designs which I wanted to have! Loads of thanks!
