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

enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.

You Might Also Like