Plot an Array of Plots as Subplots with Plots. Jl

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 Answer

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest