Matlab中的子图中心图缩放异常

3
我正在使用Matlab将来自9个不同来源的数据绘制到子图中。下面是我的图像:
每行代表不同条件下某一变量的结果。因此第1行是变量1,第2行是变量2等等。不管怎样,从图片可以看出,与第二行中的另外两个子图相比,中心子图的比例似乎有些奇怪。
我使用的代码包括以下命令:subplot(3,3,i), imagesc(data), colorbar, colormap(flipud(gray)), title('sometitle'), caxis([limits]) 我尝试通过使用ylim([0.5 3.5])设置y限制来修复中心子图,但是这没有效果...当我尝试ylim([0 4])时,会出现以下情况:
请注意,每行图中的绘图数据具有相等大小的矩阵。第1行:7x7矩阵,在第2行:3x3矩阵,在第3行:4x4矩阵。
我该如何解决这个问题? :)
感谢任何帮助!
更新:
在尝试使用以下命令后发生了什么:
subplot(3,3,5)
imagesc(data)
axis square
colorbar

这里是一个最小化的工作示例:(它显然不能完全给出相同的结果,但仍存在类似的问题):

enter image description here

data11 = rand(7,7);
data12 = rand(7,7);
data13 = rand(7,7);
data21 = rand(3,3);
data22 = rand(3,3);
data23 = rand(3,3);
data31 = rand(4,4);
data32 = rand(4,4);
data33 = rand(4,4);
subplot(3,3,1)
imagesc(data11)
colorbar
colormap(flipud(gray))
title('title')
subplot(3,3,2)
imagesc(data12)
colorbar
colormap(flipud(gray))
title('title')
subplot(3,3,3)
imagesc(data13)
colorbar
colormap(flipud(gray))
title('title')
subplot(3,3,4)
imagesc(data21)
colorbar
title('title')
subplot(3,3,5)
imagesc(data22)
colorbar
title('title')
subplot(3,3,6)
imagesc(data23)
colorbar
title('title')
subplot(3,3,7)
imagesc(data31)
colorbar
title('title')
subplot(3,3,8)
imagesc(data32)
colorbar
title('title')
subplot(3,3,9)
imagesc(data33)
colorbar
title('title')

您应该会得到类似这样的东西:

enter image description here

请注意,我是逐个输入命令(command + enter,command + enter等),然后就会出现问题,即您在帖子中看到的图片。如果我复制并粘贴整个代码(whole code + enter),则不会出现任何问题...

1
尝试在imagesc之后添加axis square,看看是否解决了问题。 - bla
1
我不知道为什么会发生这种情况,但有助于解决问题的方法是直接设置yticks。 - Lucius II.
你代码的输出在我的电脑上看起来很好(matlab 2012a,win-7 64位操作系统)。我似乎无法再现你遇到的错误。 - bla
1
很抱歉,它在我的电脑上仍然能正常运行。 - bla
1
@natan 嗯,很奇怪 :) 好吧,我想我搞定了。我只需将整个代码复制并一次性运行,而不是逐个设置它们。由于某种原因,如果我这样做就会出现问题...无论如何还是谢谢你! :) - jjepsuomi
显示剩余5条评论
1个回答

1
我会首先尝试将每个轴的“ActivePositionProperty”设置为“Position”。有关详细信息,请参阅 轴属性 的文档。
 h1 = subplot(3,3,1);
 set(h1,'ActivePositionProperty','Position');

 h2 = subplot(3,3,2);
 set(h2,'ActivePositionProperty','Position');

如果那样不行,您需要手动为每个图案设置位置属性。
 Margin = 0.1
 Width = 1 - 4*Margin;
 Height = 1 - 4*Margin;
 Left = [ (Margin) (2*Margin+Width) (3*Margin+2*Width) ];
 Bottom = [ (Margin) (2*Margin+Height) (3*Margin+2*Height) ];

 h1 = subplot(3,3,1);
 set(h1,'Position', [Left(1) Bottom(3) Width Height]);

 h2 = subplot(3,3,2);
 set(h1,'Position', [Left(2) Bottom(3) Width Height]);

 h3 = subplot(3,3,2);
 set(h1,'Position', [Left(3) Bottom(3) Width Height]);

 h4 = subplot(3,3,2);
 set(h1,'Position', [Left(1) Bottom(2) Width Height]);

 %Etc

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接