# How to plot distinct plots in grid layout

**URL:** <https://discourse.julialang.org/t/how-to-plot-distinct-plots-in-grid-layout/56242>\
**Category:** Visualization\
**Tags:** plotting, plots, layout-plots\
**Created:** [March 1, 2021, 10:45am UTC](https://discourse.julialang.org/t/how-to-plot-distinct-plots-in-grid-layout/56242 "2021-03-01T10:45:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xyz1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xyz1/32/19984_2.png) [@xyz1](https://discourse.julialang.org/u/xyz1)\
**Post date:** [March 1, 2021, 10:45am UTC](https://discourse.julialang.org/t/how-to-plot-distinct-plots-in-grid-layout/56242/1 "2021-03-01T10:45:35Z")

</div>

Hi, I’m trying to visualize some data with Plots.jl and even with the amazing Plots documentation i am unable to plot a grid (2,2) of plots.

Specifically I would like to create something like

```julia
using Plots
plot(rand(100, 4), layout = 4)

```

But with my custom plots:

```julia
using Plots

x = 1:10;
y = rand(10);
plot1 = bar(x, y);
plot2 = scatter(x, y);

plot([plot1, plot2, plot1, plot2], layout = 4)

```

but I get a lot of errors.

I tried other methods with `@layout` but I am still unable to do it. What is the correct syntax please?

---

<div class="post-metadata">

**Author:** ![xyz1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xyz1/32/19984_2.png) [@xyz1](https://discourse.julialang.org/u/xyz1)\
**Post date:** [March 1, 2021, 12:03pm UTC](https://discourse.julialang.org/t/how-to-plot-distinct-plots-in-grid-layout/56242/2 "2021-03-01T12:03:42Z")

</div>

It seems I’ve solved this issue based on [this question](https://stackoverflow.com/questions/41196010/how-to-create-an-arbitrary-number-of-subplots-in-julia-plots). I am able to plot multiple plots like this:

```julia
plots = []
for (x, y) in ...
    push!(plots, plot(x,y))
end
plot(plots...)

```

so the important part are the dots.

**However** , I tried to implement this with my example above,

```julia
using Plots

x = 1:10;
y = rand(10);
plot1 = bar(x, y);
plot2 = scatter(x, y);

plot([plot1, plot2, plot1, plot2]..., layout = 4)

```

and interestingly enough it shows only half of the plots! I tried to analyze further and found out that duplicate plots do not show in the final plot. See for example following snippet which shows an empty grid (no plots inside) for me:

```julia
x = 1:10;
y = rand(10);
plot1 = bar(x, y);
plot([plot1, plot1, plot1, plot1]..., layout=4)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 1, 2021, 12:56pm UTC](https://discourse.julialang.org/t/how-to-plot-distinct-plots-in-grid-layout/56242/3 "2021-03-01T12:56:49Z")

</div>

It works well if the plot objects are distinct, using the following simpler syntax:

```julia
plot(plot1, plot2, plot3, plot4, layout = 4)

```

---

<div class="post-metadata">

**Author:** ![xyz1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xyz1/32/19984_2.png) [@xyz1](https://discourse.julialang.org/u/xyz1)\
**Post date:** [March 1, 2021, 12:59pm UTC](https://discourse.julialang.org/t/how-to-plot-distinct-plots-in-grid-layout/56242/4 "2021-03-01T12:59:04Z")

</div>

Yes, thank you. I believe I just got confused when I couldn’t see the right output because it didn’t work for my testing code of the same plots repeated multiple times.
