# Subplots with one common legend

**URL:** <https://discourse.julialang.org/t/subplots-with-one-common-legend/60020>\
**Category:** Visualization\
**Created:** [April 26, 2021, 8:18am UTC](https://discourse.julialang.org/t/subplots-with-one-common-legend/60020 "2021-04-26T08:18:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![dmetivie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmetivie/32/6926_2.png) [@dmetivie](https://discourse.julialang.org/u/dmetivie)\
**Post date:** [April 27, 2021, 9:27am UTC](https://discourse.julialang.org/t/subplots-with-one-common-legend/60020/3 "2021-04-27T09:27:42Z")

</div>

Thanks for the link. Unfortunatly if I understand, the solution was to change the layout to add an empty subplot with only the legend. Here I don’t want to touch my layout. I just want to superpose the legend to the grid of subplots.

I think I found my answer manipulating inset plots. It just adds one line, so I think it is more robust than changing the layout, and you really can put the legend anywhere on the plot. (Drawback you might have to adjust manually the position).

```julia
D = 10
K = 4
θ = range(0, stop=2π, length=50)
r(θ) = 1 + cos(θ) * sin(θ)^2
p = [plot(proj=:polar) for j in 1:D]
[[plot!(p[j], θ, r.(θ)+0.2*rand(length(θ)), label =:none) for k in 1:K] for j in 1:D]
pall = plot(p...,size=(1200,600), layout = (2,5))
plot!(pall, (1:K)', inset = (1, bbox(2.25,0.8,0.3,0.3)), background_color=:transparent, subplot = D+1, legendfontsize=11, framestyle = :none, label=permutedims("k=".*string.(1:K)))

```

I am not exactly sure how to control the size of the legend box (it does not change with bbox) but with ‘legendfontsize’ and ‘background\_color’ it is perfect for my application.

---

_[View the full topic](https://discourse.julialang.org/t/subplots-with-one-common-legend/60020)._
