2013-10-28 36 views
1

我的代碼旨在生成一系列圖表(不同顏色),取決於percentsolar的值(因此'for'循環從1運行到長度爲percentsolar)。第一系列圖(存儲在percentimprovement1中的數組)應繪製在第一個y軸上,第二個繪圖系列(存儲在sizup21中的數組)應繪製在第2個y軸上。不幸的是,即使sizeup21中的數組不同(即它們不應該顯示爲相同的行),第二個「系列」圖也只顯示爲單一行。第二個句柄plotyy無法通過for循環

下面是我的代碼:

dashes = {':', '-'}; 
colors = {'b', 'r', 'm', 'c', 'k', 'w', 'g', 'y'}; 
for e=1:length(percentsolar) 
    [ax, h1, h2] = plotyy(randomentries, percentimprovement1(:,e), randomentries, sizeup21(:,e)); 
    set(h1,'LineStyle',dashes{1}); 
    set(h1,'color', colors{e}); 
    set(ax(1),'YLim',[0 100]); 
    set(ax(1),'YTick',0:20:100); 
    set(h2,'LineStyle', dashes{2}); 
    set(h2,'color',colors{e}); 
    set(ax(2),'YLim',[0 max(max(sizeup21))]) 
    set(ax(2),'YTick',0:1:max(max(sizeup21))) 
    hold on; 
end 
+4

做出最小的代碼,請工作,我們沒有'percentsolar,randomentries,percentimprovement1,sizeup21 ...' – bla

回答

3

沒有與plotyy和保持的問題。 plotyy創建兩個劇情手柄。保持作品不符合預期。

解決方法:

%add first tow data sets: 
[axis, l, r] = plotyy(...) 
hold(axis(1),'on') 
hold(axis(2),'on') 
%add another data set, left axis 
plot(axis(1), x, y) 
%add another data set, right axis 
plot(axis(2), x, y) 
+0

是的,有2軸與'plotyy',所以持有需要明確的語法。接得好。 – chappjc

+0

真是太棒了!謝謝。 – user2642696