2012-02-22 72 views
3

我使用plothold onhold on 繪製了多條線在另一個上面,但是如果它落在另一條線上,我希望其中一條線有點偏移。 例如在下面的情況:停止從重疊的matlab線圖

plot(1:100); hold on; plot(-100:100,abs(-100:100)) 

我希望它很清楚,這裏有2個地塊 我試圖簡單地增加對不同地塊的x值,但這偏斜的數據太多

for z=1:numberofplots 
plot((1:size(locations,2))+0.1*z,locations(z,:)','color', altclrz(z,:)); 
end 
+2

正如你可以使用linestyles像一個解決方法''--o''即離開下層線可見。 – Deve 2012-02-22 15:22:58

+4

使用另一個維度怎麼樣?使用'plot3'進行繪圖並給每個繪圖一個不同的z值。然後將視角設置爲適當的值。 – 2012-02-22 17:34:48

+0

@Deve that does not work,the spaces falling on the same area in all plots – Daniel 2012-03-01 10:18:11

回答

5

您可以區分曲線在幾個方面:

-1-扭曲了數據

正如你所說,你可以稍微移動數據。我建議你固定軸,然後在線寬計算有多少單位,所以你得到一個非常緊密的配合,如:

lineWidth = 5; 

figure(33); 
clf; 
subplot(1,2,1); 
h = plot(myData, 'linewidth', lineWidth); 
xlim([1,5]); 
ylim([1,5]); 
title('Original'); 

myData = meshgrid(1:5)'; 

myLimDiff = diff(ylim); 
set(gca,'units', 'pixels'); 
myPos = get(gca, 'position') 
myWidthHeight= myPos(3:4) 

PixelsPerUnit =myWidthHeight(2)./ myLimDiff; 
myDataSkewed = myData + meshgrid(-2:2)*1/PixelsPerUnit(1)*lineWidth; 

subplot(1,2,2); 
plot(myDataSkewed, 'linewidth', lineWidth); 
xlim([1,5]); 
ylim([1,5]); 
title('Skewed'); 

結果:

enter image description here

-2-使用固體線和橫線

正如有人在評論別人注意,你可能在你的虛線在實線,或風格的一些組合。

-3-使用不同線寬

使用不同的行與最厚的底部寬度:

figure(54); 
clf 
hold all 
for ind = 10:-3:1 
    plot(1:5, 'linewidth', ind); 
end 

enter image description here

-4-使用單獨繪製每個線扭曲

An另一種調出每條線的方式是繪製一條子圖中的每條線,但首先將所有數據繪製成灰色。這樣,您就可以看到所有的線與叫出每個特定行:

enter image description here

figure(55); 
clf 
data = rand(3); 

for ind = 1:3  
    subplot(1,3,ind); 
    plot(data, 'linewidth', 4, 'color', [1 1 1]*.75); 
    hold on 
    plot(data(:,ind), 'linewidth', 2); 
end 
+0

到目前爲止,大多數想法的問題是我有很多地塊,通常超過50個。這使得2,3和4不適用。 1看起來非常好,我馬上檢查一下。(我希望它的作品,如果情節是分開使用保持) – Daniel 2012-05-31 13:19:55

+1

+1的想法4,即使OP不能使用它,我認爲這是一個很好的解決方案。 – nispio 2013-11-06 06:03:11