Prevent crowding of subplots in Plots.jl

plotting

#1

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:

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

#2

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:

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:

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:

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.


#3

Thanks for your help!