2013-05-26 22 views
2

我有问题来设置子图的位置。我在循环中使用子图。但是,当我尝试对子图做出特殊定位时,它不起作用。这是我的代码:如何在MATLAB中定位子图?

h=subplot(2,2,3); 
set(h,'position',[0.15 0.15 0.4 0.4]); 
plot(d3,S3,'*','Color',colors(i,:)); 

我尝试了不同的方法,但不能看到第三个插曲,有时情节只显示一个迭代。

我该如何解决这个问题?

回答

2

这会创建3个子图。位置是[左下宽度高度])。我通常会尝试确保左侧的宽度为+ < 1,底部+高度为< 1(对于第一个子图)。

figure 
set(subplot(3,1,1), 'Position', [0.05, 0.69, 0.92, 0.27]) 
set(subplot(3,1,2), 'Position', [0.05, 0.37, 0.92, 0.27]) 
set(subplot(3,1,3), 'Position', [0.05, 0.05, 0.92, 0.27]) 

如果您只有1列子图,此方法效果良好。对于次要情节的两列是使用:

figure 
subplot(4,2,1) 
plot(...) 
set(gca, 'OuterPosition', [0, 0.76, 0.49, 0.23]) 
subplot(4,2,2) 
plot(...) 
set(gca, 'OuterPosition', [0.48, 0.76, 0.49, 0.23]) 
subplot(4,2,3) 
... 
+0

非常感谢你 – hola

+0

@m_power你告诉我你是如何计算设置参数的值。我经历了matlab中的文档,但无法得到它的窍门 – roni

3

这可能是因为副房间瓦片号码(即subplot(2,2,3)等)与其自己的默认位置以及您输入的位置之间的位置冲突值而发生的。

所以改用插曲只是位置信息如下:

subplot('position', [0.15 0.15 0.4 0.4]) 
plot(d3,S3,'*','Color',colors(i,:)); 
subplot('position', [... ... ... ...]) 
plot(...); 

this SO discussion看到...

+0

我试过了,但得到同样的问题.... – hola

+0

请加你试过SP,我们可以看到有什么问题的代码。 – bla

2

根据subplot

副区( '位置',[左底宽高度])在由四元素矢量指定的位置创建轴。左侧,底部,宽度和高度值为标准化坐标,范围从0.0到1.0。

另请注意,左侧和底部的值是从图的左下方算起的。


这里是一个在for循环中使用子图的例子。

figure 

% subplot dimension 
n1 = 2; % number of rows 
n2 = 3; % number of columns 

% These values would define the space between the graphs 
% if equal to 1 there will be no space between graphs 
nw = 0.9; % normalized width 
nh = 0.9; % normalized height 

for k1 = 1:n1 
    for k2 = 1:n2 
     subplot(n1,n2,(k1-1)*n2 + k2,... 
      'position', [(1-nw)/n2/2 + (k2-1)/n2, (1-nh)/n1/2 + 1-k1/n1,... 
      nw/n2 nh/n1]); 
     % plot something 
     plot(rand(5)); 
     % turn off the labels if you want 
     set(gca, 'XTick', []); 
     set(gca, 'YTick', []); 
    end 
end 

希望这会有所帮助。

+0

非常感谢你 – hola

+0

在Matlab 2016b中:当第二个绘图生成并保持太小时,第一个绘图被调整大小。为了让它在Matlab 2016b中工作,必须改变什么? –

相关问题