2014-12-23 71 views
1

我想在Matlab中创建两个y轴图。 我有两组数据,每组有三个类似的图。当我试图绘制它时,右侧y轴上的缩放比例会变得混乱。我希望得到一些帮助。在Matlab中有多个数据集的两个y轴图

X = [50, 100, 200, 400]; 

YSKL_Temporal_WOFAE = [3.2000  2.3354  1.9428   1.7658]; 
YSKL_Spatial_WOFAE  = [0.9225  0.9724  1.0986   1.1770]; 
YSKL_Spatial_WithFAE = [0.2635  0.1653  0.1513   0.1618]; 

YMSRE_Temporal_WOFAE = [0.3559  0.3027 0.2733   0.2636]; 
YMSRE_Spatial_WOFAE  = [.3151  .2689  .2551   0.2524]; 
YMSRE_Spatial_WithFAE = [.0933  .0648  0.0663   0.0640]; 

figure(1); 
[AX, p1, p2] = plotyy(X, YSKL_Temporal_WOFAE, X, YMSRE_Temporal_WOFAE); 
set(AX,'XTick', X); % This fixes X-axis tick mark (same as data axis) 

set(get(AX(1),'Ylabel'),'String','SKL Score') 
set(get(AX(2),'Ylabel'),'String','Norm. Residuals') 
xlabel('Time (\musec)') 
title('SKL and Norm. Residual plotted on different y-axes') 
set(p1,'LineStyle','--') 
set(p2,'LineStyle',':') 

axes(AX(1)) 
hold on 
plot(X, YSKL_Spatial_WOFAE); 
hold on 
plot(X, YSKL_Spatial_WithFAE); 
ylim([0 4]) 
hold off 

axes(AX(2)) 
hold on 
plot(X, YMSRE_Spatial_WOFAE); 
hold on 
plot(X, YMSRE_Spatial_WithFAE); 
ylim([0.0 0.4]) 
hold off 

剧情看起来像这样: enter image description here

请注意在右侧y轴

问候规模, Dushyant

回答

2

第二(右手侧)的y轴的刻度在致电plotyy后,标签被“冻结”。当调整 AX(2)时,这对标签没有影响。
因此,axes appearance必须重置为auto
使用下面的代码与问题的例子:

axes(AX(2)) 
hold on 
plot(X, YMSRE_Spatial_WOFAE); 
hold on 
plot(X, YMSRE_Spatial_WithFAE); 
ylim([0.0 0.4]) 
% include the following statement to allow 
% the second y-axis to reset the ticks: 
set(AX(2), 'YTickMode', 'auto', 'YTickLabelMode', 'auto') 
hold off 

会产生这样的情节:

enter image description here

+0

感谢了很多帮助我的。另外,请接受我的歉意,以便延迟接受您的答案。我正在度假,没有上网。 –