Plot images within a loop

I am trying to plot some data within one loop using the following code:

n=length(B)
for i in 1:n
i=contourf(x,y,B[i], layout=n)
display(i)
end

Here B is a matrix and each B[i] is one array. When using the above code, it only output one image and some others are overlapped, as shown below. I am wondering how could I plot all the images as a function of i. Thanks
image

Maybe try the following?

julia> ps = map(1:4) do s
           x = rand(100)
           y = s * x .+ rand(100)
           scatter(x, y, ylim = [0, 5])
       end
4-element Vector{Plots.Plot{Plots.GRBackend}}:
 Plot{Plots.GRBackend() n=1}
 Plot{Plots.GRBackend() n=1}
 Plot{Plots.GRBackend() n=1}
 Plot{Plots.GRBackend() n=1}

julia> plot(ps...)

or:

julia> using Plots

julia> plt = plot(layout=(2,3)) # create plot object with the desired layout

julia> for i in 1:6
           plot!(plt, rand(10), subplot=i) # plot each set in a different subplot
       end

julia> display(plt)

I tried using above way, but no data was plotted, maybe I had missed something. Here is my code:

n=length(B)
plt=plot(layout=n)
for i in 1:n
plot!(plt, contourf(xs,ys,B[i]), subplot=i)
end
display(plt)

image

this should be just

contourf!(plt, xs, ys, B[i], subplot=i)

the contourf! replaces the plot!call, which is for plotting lines.

1 Like

I see, now it works. Thank you!