Plotting 16 plots in one figure using handle graphics

2 ビュー (過去 30 日間)
Maria Galle
Maria Galle 2020 年 12 月 3 日
コメント済み: Ameer Hamza 2020 年 12 月 8 日
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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by