# Plot legend with multiple columns

**URL:** <https://discourse.julialang.org/t/plot-legend-with-multiple-columns/29195>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [September 26, 2019, 1:15pm UTC](https://discourse.julialang.org/t/plot-legend-with-multiple-columns/29195 "2019-09-26T13:15:18Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 30, 2021, 7:29pm UTC](https://discourse.julialang.org/t/plot-legend-with-multiple-columns/29195/7 "2021-06-30T19:29:22Z")

</div>

@kongdd, one workaround is to use [insets](https://discourse.julialang.org/t/subplots-with-one-common-legend/60020/3), but example would definitely require more plumbing:

```julia
using Plots; gr()

# define n-curves and n-labels
n = 7
x = 0:0.1:6π
yk = [k*sin.(x .- k) .* exp.(-0.02*k*x) for k in 1:n]
labels = " k = " .* string.(1:n) .* " "

# plot n-curves and legend with n-labels over 2 columns
ncolors = distinguishable_colors(n, [RGB(0,1,1), RGB(0,0,0)], dropseed=false)
n2 = ceil(Int,n/2)
b = 0.15 # adjust this function of legend sizes
p = plot(x,yk, xlabel="x", ylabel="y", color=ncolors', legend=false, widen=false)
plot!(p, (1:n2)', color=ncolors[1:n2]', inset=(1, bbox(1-2*b,0,b,1,:left)), bg=:transparent,
      subplot=2, legendfontsize=10, border=:none, label = permutedims(labels[1:n2]),
      bg_legend=:white, fg_legend=nothing, axes=false)
plot!(p, (n2+1:n)', color=ncolors[n2+1:n]', inset=(1, bbox(1-b,0, b,1,:left)), bg=:transparent,
      subplot=3, legendfontsize=10, border=:none, label = permutedims(labels[n2+1:n]),
      bg_legend=:white, fg_legend=nothing, axes=false)

```

![Plot_gr_insets_for_legends_in_2_columns](https://global.discourse-cdn.com/julialang/original/3X/8/e/8ef688a2fd78c487925dd8856fa26c8000b5a4cf.png)

---

_[View the full topic](https://discourse.julialang.org/t/plot-legend-with-multiple-columns/29195)._
