# Common legend using layouts

**URL:** <https://discourse.julialang.org/t/common-legend-using-layouts/45553>\
**Category:** General Usage\
**Tags:** plotting, layout-plots\
**Created:** [August 26, 2020, 7:14am UTC](https://discourse.julialang.org/t/common-legend-using-layouts/45553 "2020-08-26T07:14:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drarnau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drarnau/32/4476_2.png) [@drarnau](https://discourse.julialang.org/u/drarnau)\
**Post date:** [August 26, 2020, 7:14am UTC](https://discourse.julialang.org/t/common-legend-using-layouts/45553/1 "2020-08-26T07:14:10Z")

</div>

Dear all,

I am plotting this:

```julia
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?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 28, 2020, 1:24am UTC](https://discourse.julialang.org/t/common-legend-using-layouts/45553/2 "2020-08-28T01:24:26Z")

</div>

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

```julia
plot(layout=(2,5))
plot!(rand(32),subplot=1,label="blue")
plot!(rand(32),subplot=1,label="orange")
for sp in 2:10
   plot!(rand(32),subplot=sp,label="")
end
plot!()

```

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

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 28, 2020, 12:03pm UTC](https://discourse.julialang.org/t/common-legend-using-layouts/45553/3 "2020-08-28T12:03:18Z")

</div>

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:

```julia
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));
end
p = plot(pV..., layout = (2,5));

```

---

<div class="post-metadata">

**Author:** ![drarnau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drarnau/32/4476_2.png) [@drarnau](https://discourse.julialang.org/u/drarnau)\
**Post date:** [August 28, 2020, 12:24pm UTC](https://discourse.julialang.org/t/common-legend-using-layouts/45553/4 "2020-08-28T12:24:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 28, 2020, 1:07pm UTC](https://discourse.julialang.org/t/common-legend-using-layouts/45553/5 "2020-08-28T13:07:57Z")

</div>

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

[http://juliaplots.org/MakieReferenceImages/gallery//faceting/index.html](http://juliaplots.org/MakieReferenceImages/gallery//faceting/index.html)

Other examples are available at: [http://juliaplots.org/MakieReferenceImages/gallery/index.html](http://juliaplots.org/MakieReferenceImages/gallery/index.html)
