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.