2012-04-01 76 views
3

是否可以用2個yaxis生成pcolor圖?pcolor plot上的第二個y軸

考慮下面的例子:

clear all 
temp = 1 + (20-1).*rand(365,12); 
depth = 1:12; 
time =1:365; 

data2 = 1 + (60-1).*rand(12,1); 
time2 = [28,56,84,124,150,184,210,234,265,288,312,342]; 

figure; 
pcolor(time,depth,temp');axis ij; shading interp 
hold on 
plot(time2,data2,'w','linewidth',3); 

相反在相同的y軸上標繪所述第二數據集的我想它放置在其自己的y軸上。這可能嗎?

回答

1

您需要在pcolor軸的頂部添加其他軸,匹配它們的位置,然後繪圖。您可以在頂部(X)和右側(Y)上設置軸位置。如果他們假設匹配LINKAXES,請不要忘記鏈接X軸。

pcolor(time,depth,temp');axis ij; shading interp 
ax1 = gca; 
%# new axes with plot 
ax2 = axes('position',get(ax1,'position'),'color','none'); 
set(ax2,'YAxisLocation','right', 'XAxisLocation','top') 
hold on 
plot(ax2,time2,data2,'w','linewidth',3); 
hold off 
linkaxes([ax1 ax2], 'x'); 

pcolor with line

0

我不確定你的意思。 如果您想要相同的軸但不同的y值,請嘗試plotyy。如果您需要兩個不同的軸,請嘗試使用命令subplot

+0

從你寫什麼,我更想找plotyy涉及解決方案,但我不能讓plotyy與一個令pColor情節工作。 – Emma 2012-04-01 16:12:11