Using Layout properly for Multiple plots in same box

Hi all, I’m trying to get 2 plots (one on top of the other) in the same box, using the layout command, but I can’t seem to get the syntax right without errors.

Julia’s document lists some examples using random numbers, such as:
plot(rand(100, 4), layout = (4, 1))
but, I have arrays of actual values to plot. So my current plotting command is something like:
plot(xArray1[1:end], yArray1[1:end], color="blue"); plot!(xArray2[1:end], yArray2[1:end], color="red")

How to use layout = (2,1) the correct way to separate these plots and put them one on top of another? Thanks…!

Hi again, any ideas for the correct syntax for this? Googling the layout command and trial-and-error haven’t helped so far. Thank you.

You can try to use below

using Plots

plt1 = plot(sin, 0:2\pi)
layout_setting = @layout [a;b;c d]
plot(plt1, plt1, plt1, plt1, layout = layout_setting)

you may find the macro layout provides what you want.

[a;b;c d] # the semicon ; separate the rows, and space sepearte the columns

Hello JulesJyu, I have adapted your suggestion to my 2-plot attempt, and it works, thank you!

My final (working) code:

using Plots

xArray1 = rand(15); yArray1 = rand(15);
xArray2 = rand(15); yArray2 = rand(15);

plt1 = plot(xArray1, yArray1, color="blue");
plt2 = plot(xArray2, yArray2, color = "red");

layout_setting = @layout [a;b]
plot(plt1, plt2, layout = layout_setting)