How can I increase the space between subplots in Plots.jl?
Minimal non-working example:
julia> using Plots; pyplot()
Plots.PyPlotBackend()
julia> data = [rand(100), rand(100)];
histogram(data, layout=2, title=["Dataset A" "Dataset B"], legend=false)
ylabel!("ylabel")
If you make the figure small enough, the y label of the second plot collides with the first plot.
In the attributes part of Plots.jl
documentation, there is a section called Subplot. There, you will find the keywords margin
, top_margin
, bottom_margin
, left_margin
and right_margin
that might help you.
Minimal working example would be, then:
using Plots, Measures
pyplot()
data = [rand(100), rand(100)];
histogram(data, layout = 2,
title = ["Dataset A" "Dataset B"], legend = false,
ylabel = "ylabel", margin = 5mm)
Note the using Measures
part, by the way. I hope this helps.
Another workaround would be using the bottom_margin
keyword argument holding the pyplot
backend like this:
using Plots
pyplot()
x1 = rand(1:30, 20);
x2 = rand(1:30, 20);
# subplot 1
p1 = plot(
x1,
label="x1 value",
title="x1 line plot",
ylabel="x1",
bottom_margin=50*Plots.mm,
);
# subplot 2
p2 = plot(
x2,
label="x2 value",
title="x2 line plot",
xlabel="sample",
ylabel="x2",
);
plot(
p1,
p2,
layout=grid(
2,1,
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With