# Problems with legend

**URL:** <https://discourse.julialang.org/t/problems-with-legend/55105>\
**Category:** New to Julia\
**Created:** [February 12, 2021, 12:46am UTC](https://discourse.julialang.org/t/problems-with-legend/55105 "2021-02-12T00:46:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 12, 2021, 12:46am UTC](https://discourse.julialang.org/t/problems-with-legend/55105/1 "2021-02-12T00:46:58Z")

</div>

Hello users,  
How can I insert a legend correctly on my plots in a layout 3 x 3?  
Below my code:

```julia
using Plots
plotly()

function Euler(f,a,b,α,n)
    h = (b-a)/n
    w=zeros(1+n)
    w[1]=α
    t = [a + i*h for i in 0:n]
    for i in 1:n
        w[i+1] = w[i] + h*f(t[i],w[i])
    end
    t=round.(t,digits=4)
    w=round.(w,digits=4)
    return (t,w)
end

f(t,y) = (2/t)*y + (t^2)*exp(t)
α = 0;
a = 1; b = 2;
n = 10;
ϕ(t) = (t^2)*(exp(t) - exp(1))

g = plot(;leg=false,layout=(3,3),size=(800,800),label = ["exato" "Euler"])
p=1
n=[3,6,9,12,15,18,21,24,27]
for i=1:3, j=1:3
    k=n[p]
    (t,w) = Euler(f,a,b,α,k)
    plot!(g[p],ϕ,1:0.001:2,color="blue",lw=2,label="exato")
    plot!(g[p],t,w,color="orange",lw=2,
    title="n = $k",titlefontsize=10,line=:dot,marker=:circle,label="Euler")
    ylims!(g[p],-1,22)
    xlims!(g[p],0.9,2.6)
    p=p+1
end
g

```

and the plots without legend generated by my code. I would like to insert `exact` to blue line and `Euler` to orange in each subplot, not showed below.

 ![plots](https://global.discourse-cdn.com/julialang/original/3X/d/9/d97b48796abd70ae2993362b9627262ceea3b106.png)

---

<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:** [February 12, 2021, 3:26pm UTC](https://discourse.julialang.org/t/problems-with-legend/55105/2 "2021-02-12T15:26:37Z")

</div>

I usually generate the plots first and the assemble them:

```julia
using Plots

pV = Vector{Any}(undef, 2);
for j = 1 : 2
    pV[j] = plot(1:10, j .* (1:10); label = "Plot $j", legend = :bottom);
end

p = plot(pV...; layout = (1,2))

```

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [February 12, 2021, 4:47pm UTC](https://discourse.julialang.org/t/problems-with-legend/55105/3 "2021-02-12T16:47:26Z")

</div>

However, when I use polar coordinates this don’t works:

```julia
pV = Vector{Any}(undef, 3);
theta = 0:2*pi/1000:2*pi+2*pi/1000
for j = 1 : 3
    r=(cos.(j*theta))
    pV[j] = plot(theta,r,proj=:polar,linewidth = 4,color=:red,legend = :top)
end

p = plot(pV...; layout = (1,3),size=(800,800))

```

---

<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:** [February 12, 2021, 7:55pm UTC](https://discourse.julialang.org/t/problems-with-legend/55105/4 "2021-02-12T19:55:40Z")

</div>

What part does not work?

For me, it produces 3 subplots, each with its own legend.
