Problems with legend

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

``````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.

I usually generate the plots first and the assemble them:

``````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))
``````
2 Likes

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

``````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))
``````

What part does not work?

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