Subplots in Plots.jl with individual axis labels

How do I specify - in the example below - the y-labels individually for the two subplots?

I am having a hard time finding just a single example of subplot where the xlabel and ylabel have been used/demonstrated.


using Plots

gr(size=(400,400), legend= false)

x = 0:100
y = x.^2
z = sqrt.(x)

l = @layout([a;b])
plot(x, [y z], layout=l, xlabel="x", ylabel="y")

I tend to build the plots separately and bring them all together at the end.

using Plots

gr(size=(400,400), legend=false)

x = 0:100
y = x.^2
z = sqrt.(x)

p1 = plot(x, y)

p2 = plot(x, z)
xaxis!("Another x")
yaxis!("Another y")

plot(p1, p2, layout=(2,1))

I quite like this approach, because I get to look at all of the subplots individually before I put them all together.


You can put two strings for ylabel in a 1x2 matrix just as you provided the y-series

1 Like

Thank you JackDevine!
Very nice and simple! Much much better (i.e. more intuitive) than what I had finally managed to dig up:

p.spmap[:a][:yaxis].d[:guide] = "z"
p.spmap[:b][:yaxis].d[:guide] = "y"

Thank you baggepinnen, I initially tried but used the wrong syntax:

plot(x, [y z], layout=l, xlabel="x", ylabel=["z" "y"])

works too!


Well spotted, both group and the “horizontal concatenation” syntax (like [x y]) create several series. If layout == 1 they are plotted together with different colors, otherwise they are distributed across subplots.