A list of plots as an argument for the plot-command of Plots.jl

If you consider the following code, you will get a list of plots.

using Plots
plotly()


var_names = ["var1", "var2", "var3"]

# initialize regression matrices for training, validation and test
X1 =  rand(20, 3)
X2 =  rand(15, 3)
X3 = rand(10, 3)


function plot_space(list_data, var_names)
    num_dim = size(list_data[1], 2)
    num_plots = num_dim*(num_dim-1)/2
    list_plots = [scatter(list_data[1][:, 1], list_data[1][:, 2], xlabel=var_names[1], ylabel=var_names[2])]
    for i in 1:num_dim        
        for j in max(3, i+1):num_dim
            if !(i==1 && j==2)
                push!(list_plots, scatter(list_data[1][:, i], list_data[1][:, j], xlabel=var_names[i], ylabel=var_names[j]))
            end
            for k in 2:length(list_data)
                scatter!(list_plots[end], list_data[k][:, i], list_data[k][:, j]);
            end
            println("($i,$j)")
        end
    end
    return list_plots
end

list_plots = plot_space([X1, X2, X3], var_names)

Then it would be nice to plot the plots listed in the list with plot(list_plots, layout = (3, 1)) or something similar? Is there already something similar?

You can use splatting:

plot(list_plots..., layout = (3, 1))
3 Likes

Thank you very much.