Common legend using layouts

Dear all,

I am plotting this:

plot(rand(32,10), layout = (2,5), legend=false)
plot!(rand(32,10), layout = (2,5), legend=false)

And I’d like to have just one legend saying what the blue lines stand for and what the orange lines stand for. Anybody knows how to make it happen?

If you don’t mind having the legend inside the first plot, you can do:

for sp in 2:10

If you do mind, there are sophisticated plot layouts that can be obtained using Makie.jl

1 Like

I usually end up building subplots from individual plots because I find that various settings differ by subplot (e.g., only showing x axis labels on the plots in the bottom row; only showing y axis labels for the left most column).
So I do:

pV = Vector{Any}(undef, n);
for j = 1 : n
  # can customize axis labels etc here
  pV[j] = plot(<data>, labels = ["blue" "red'], legend = (j == 1));
p = plot(pV..., layout = (2,5));
1 Like

Those are useful. I’ve end up doing something similar. However, it’s not quite what I was looking for. I wanted one common legend, to be placed for example outside the plot region, common for all subplots. That seems not to be possible.

The Makie package provides tools to do almost anything. For example:

Other examples are available at: