Plotting 16 plots in one figure using handle graphics

2 次查看(过去 30 天)
I'm trying to plot 16 plots in one figure window to make a 4x4 grid using handle graphics and NOT using subplot. I'm trying to use a for loop to make the plots. I'm getting 16 of the same plot instead of 16 different plots (magic(5), magic(6),magic(7)...etc).
k = 4;
dim = 0.8/k-0.05;
axs = gobjects(k);
for i = 1:k
for j = 1:k
for N=5:20
data = magic(N);
axs(i,j) = axes();
zp=imagesc(data);
xloc = interp1([1, k], [0.1, 0.9-dim], j);
yloc = interp1([1, k], [0.9-dim, 0.1], i);
axs(i,j).Position = [xloc yloc dim dim];
end
end
end

采纳的回答

Ameer Hamza
Ameer Hamza 2020-12-3
Try this
n = 4;
dim = 0.8/n-0.05; % considering that the axes will go from 0.1 to 0.9 in figure coordinates
% and leaving space between axes
axs = gobjects(n);
for i = 1:n
for j = 1:n
axs(i,j) = axes();
xloc = interp1([1, n], [0.1, 0.9-dim], j);
yloc = interp1([1, n], [0.9-dim, 0.1], i);
axs(i,j).Position = [xloc yloc dim dim];
end
end
  4 个评论
Maria Galle
Maria Galle 2020-12-8
I'm trying to make 2d plots of 16 matrices using imagesc. I want to plot 16 magic matrices, magic(N) for N=5:20. My 16 different datasets are the 16 magic matrices for each value of N.
Ameer Hamza
Ameer Hamza 2020-12-8
Try this code
n = 4;
dim = 0.8/n-0.05; % considering that the axes will go from 0.1 to 0.9 in figure coordinates
% and leaving space between axes
axs = gobjects(n);
N = 5;
for i = 1:n
for j = 1:n
axs(i,j) = axes();
xloc = interp1([1, n], [0.1, 0.9-dim], j);
yloc = interp1([1, n], [0.9-dim, 0.1], i);
axs(i,j).Position = [xloc yloc dim dim];
M = magic(N);
N = N+1;
imagesc(M)
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by