# Prevent crowding of subplots in Plots.jl

**URL:** <https://discourse.julialang.org/t/prevent-crowding-of-subplots-in-plots-jl/8716>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [January 31, 2018, 2:11pm UTC](https://discourse.julialang.org/t/prevent-crowding-of-subplots-in-plots-jl/8716 "2018-01-31T14:11:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [January 31, 2018, 2:11pm UTC](https://discourse.julialang.org/t/prevent-crowding-of-subplots-in-plots-jl/8716/1 "2018-01-31T14:11:49Z")

</div>

I have a 2x2 grid of subplots in Plots.jl. The button row of plots are plotted on top of x-axis label of the plots on the top row. Is there a simple way to prevent this from happening? Here is a MWE:

```julia
using Plots
plotlyjs()
plot(layout = 4,xlims=(-3,3),leg=false)
for i in 1:4
    histogram!(randn(10000),norm=true,color=:grey,xaxis = "Values",yaxis = "Density",subplot=i)
end
plot!()#show plot

```

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [January 31, 2018, 2:36pm UTC](https://discourse.julialang.org/t/prevent-crowding-of-subplots-in-plots-jl/8716/2 "2018-01-31T14:36:10Z")

</div>

A couple of unrelated points: it’s a bit unconvential to use `plot!()` to get the plot to show up. A more conventional way would be:

```julia
plt = plot(layout = 4,xlims=(-3,3),leg=false)
for i in 1:4
    histogram!(plt, randn(10000),norm=true,color=:grey,xaxis = "Values",yaxis = "Density",subplot=i)
end
display(plt)

```

Also, note that the same plot can be achieved with the following syntax:

```julia
histogram(randn(10000, 4),norm=true,color=:grey,xaxis = "Values",yaxis = "Density",
    layout = 4, xlims = (-3, 3))

```

The keyword you are looking for is `margin`, so:

```julia
using Plots.Measures
histogram(randn(10000, 4),norm=true,color=:grey,xaxis = "Values",yaxis = "Density",
    layout = 4, xlims = (-3, 3), margin = 5mm)

```

should give you more space. You can use `top_margin`, `left_margin` etc. to only add margin along some directions.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [January 31, 2018, 2:40pm UTC](https://discourse.julialang.org/t/prevent-crowding-of-subplots-in-plots-jl/8716/3 "2018-01-31T14:40:49Z")

</div>

Thanks for your help!
