# Plot in even grid layout when the number of subplots is prime (using Plots.jl)

**URL:** <https://discourse.julialang.org/t/plot-in-even-grid-layout-when-the-number-of-subplots-is-prime-using-plots-jl/53206>\
**Category:** General Usage\
**Tags:** plotting, plots, layout-plots\
**Created:** [January 12, 2021, 2:01pm UTC](https://discourse.julialang.org/t/plot-in-even-grid-layout-when-the-number-of-subplots-is-prime-using-plots-jl/53206 "2021-01-12T14:01:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sh4pe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sh4pe/32/10537_2.png) [@Sh4pe](https://discourse.julialang.org/u/Sh4pe)\
**Post date:** [January 12, 2021, 2:01pm UTC](https://discourse.julialang.org/t/plot-in-even-grid-layout-when-the-number-of-subplots-is-prime-using-plots-jl/53206/1 "2021-01-12T14:01:46Z")

</div>

Hi there!

I’m using Plots.jl and I’m trying to customize a layout. I want to draw some plots in a grid layout, kind of like they are arranged when I don’t specify a layout at all.

Say we have the following situation:

```julia
let
	hs = [histogram(rand(100)) for _ in 1:13]
	plot(hs..., fmt=:png)
end

```

This results in this plot:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/c/3cb2dacce79a2a3478d0e6acbc1794f361d0b93c.png)

Now I’d like to plot these with only three columns. Note that the total number of plots is prime, i.e. there is no way to generate a `grid(n,m)` such that the number of grid cells match, I’ll always run into this `n != n_override` problem. But what I want is to have an evenly spaced grid with some plots missing at the end.

How to do this? I couldn’t figure it out. It must works since the default layout does kind of the same thing, only with a number of columns that doesn’t fit my needs.

Thanks!

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [January 12, 2021, 4:16pm UTC](https://discourse.julialang.org/t/plot-in-even-grid-layout-when-the-number-of-subplots-is-prime-using-plots-jl/53206/2 "2021-01-12T16:16:48Z")

</div>

There should be a cleaner way to do this, but if you don’t mind some hackery, you can just insert blank plots.

```julia
let
	hs = [histogram(rand(100)) for _ in 1:13]
	
	ncols = 3
	nrows = cld(length(hs), ncols)
	blankplot = plot(legend=false,grid=false,foreground_color_subplot=:white)
	for i = (length(hs)+1):(nrows*ncols)
		push!(hs, deepcopy(blankplot))
	end
	plot(hs..., fmt=:png, layout=grid(nrows, ncols))
end

```

---

<div class="post-metadata">

**Author:** ![Sh4pe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sh4pe/32/10537_2.png) [@Sh4pe](https://discourse.julialang.org/u/Sh4pe)\
**Post date:** [January 13, 2021, 9:40am UTC](https://discourse.julialang.org/t/plot-in-even-grid-layout-when-the-number-of-subplots-is-prime-using-plots-jl/53206/3 "2021-01-13T09:40:36Z")

</div>

Cool, I don’t mind a bit of a hack. 🙂
