Plotting variable number of subplots in a plot

Ho do I plot a variable number of subplots in a single common plot. For example, the following simple code

using Plots;
plotlyjs();

N = 3;
Q = Array{Plots.Plot, 1}(undef, N);
for n in 1:N
    Q[n] = plot(rand(4));
end
P = plot(Q, layout = (N,1));

leads to the error

ERROR: LoadError: MethodError: no method matching Plots.Plot{Plots.PlotlyJSBackend}(::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char)
Closest candidates are:
  Plots.Plot{Plots.PlotlyJSBackend}(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) where T<:AbstractBackend at C:\Users\iamsu\.julia\packages\Plots\NVH6y\src\types.jl:68
Stacktrace:
 [1] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.Plot{Plots.PlotlyJSBackend}}, ::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\iamsu\.julia\packages\Plots\NVH6y\src\recipes.jl:50
 [2] _apply_type_recipe(::Dict{Symbol,Any}, ::Array{Plots.Plot,1}, ::Symbol) at C:\Users\iamsu\.julia\packages\RecipesPipeline\NRqoc\src\type_recipe.jl:36
 [3] macro expansion at C:\Users\iamsu\.julia\packages\RecipesPipeline\NRqoc\src\user_recipe.jl:144 [inlined]
 [4] apply_recipe(::Dict{Symbol,Any}, ::Array{Plots.Plot,1}) at C:\Users\iamsu\.julia\packages\RecipesBase\FlaiX\src\RecipesBase.jl:281
 [5] _process_userrecipes!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Plots.Plot,1}}) at C:\Users\iamsu\.julia\packages\RecipesPipeline\NRqoc\src\user_recipe.jl:35
 [6] recipe_pipeline!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Plots.Plot,1}}) at C:\Users\iamsu\.julia\packages\RecipesPipeline\NRqoc\src\RecipesPipeline.jl:67
 [7] _plot!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Plots.Plot,1}}) at C:\Users\iamsu\.julia\packages\Plots\NVH6y\src\plot.jl:167
 [8] plot(::Array{Plots.Plot,1}; kw::Base.Iterators.Pairs{Symbol,Tuple{Int64,Int64},Tuple{Symbol},NamedTuple{(:layout,),Tuple{Tuple{Int64,Int64}}}}) at C:\Users\iamsu\.julia\packages\Plots\NVH6y\src\plot.jl:57
 [9] top-level scope at C:\ShobKichhu\Julia\t.jl:9
 [10] include(::String) at .\client.jl:457
 [11] top-level scope at REPL[1]:1
in expression starting at C:\ShobKichhu\Julia\t.jl:9

Splatting the vector of Plots works:

P = plot(Q..., layout = (N,1));
2 Likes

It worked! Thanks!