Subplot of heatmap in Plots

Hi

i have a vector of images that need to plot in heatmap, i want to display all of them in an grid subplots,

the Plots doc shows that the easiest way is to use heatmap(a,layout=grid(3,3) given a=array(matrix,9). but it seems Plots don’t know how to automatically map each image to each subplot in grid.

my questions is whether this simple use is possible in Plots, or i have to iterately plot each image in subplots, and how to do that?

It is hard to guess what you want without some sort of example involving runnable code. I think that I have guessed what you want and I have tried my best below. The basic idea is that you can make an array of plots called ps which you then splat into the plot command.

using Plots; gr()
nimages = 9

a = [rand(50, 50) for _ in 1:nimages]
ps = []
for i in 1:nimages
     push!(ps, heatmap(a[i]))
end

plot(ps..., layout=(3, 3))
2 Likes

ok, it seems vector of images or cat(3,imgaes…) does’t map in subplot grid.

so i made each plot, and map it to subplot.

using Plots; pyplot()
plot(heatmap.(a,color=:gray,aspect_ratio=:equal,legend=false)...,layout=(3,4))

and it show this

1, it seems that the vector of plots are maped in subplot grid in row-wise manner, ie, a[1] is mapped in grid[1,1], a[2] in grid[1,2], etc. is there a way to mannully set which grid cell to place a subplot ,such as plot(…, gridcell= (1,3)) ?

2, i also want to hide the whole axis, or make the axis line as box enclose the plot area, and make the interval among subplot small, how to do that?

For complex layouts, check Layouts · Plots

by an example, i can get layout showing right subplot in gridcell, but some subplot axis line still shows which i want to eliminate by setting axis=nothing. how can i hide all axis stuff?

using Plots;pyplot()

a = [rand(20,20) for _ in 1:3]
p=plot(layout=grid(2,2),leg=false,axis=nothing)
for i=1:3
    plot!(p[i],a[i],seriestype=:heatmap,ratio=:equal)
end
p

and i got:

Try framestyle = :none rather than axis = nothing.