Plot an array of plots as subplots with Plots.jl

Viewed 805

Continuation of this thread: How to create an arbitrary number of subplots in Julia Plots

When I tried

using Plots
plot_array = Any[] 
for i in 1:5
    push!(plot_array, plot(rand(10))) # make a plot and add it to the plot_array
end
plot(plot_array)

I received Error:

MethodError: no method matching Plots.Plot{Plots.PlotlyBackend}(::Char, ::Char, ::Char, ::Char, ...) 
Closest candidates are: Plots.Plot{Plots.PlotlyBackend}(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)

What did I miss?

1 Answers

You need to "splat" the array of subplots in the last plot call using ...:

using Plots
plot_array = [] 
for i in 1:5
    push!(plot_array, plot(rand(10)))
end
plot(plot_array...) # note the "..." 

will produce something like

enter image description here

Related