停止matlab线图重叠

Dan*_*iel 3 matlab plot

我使用了多条线,plot并且hold on 如果它落在另一条线上,我希望其中一条线移动一点.例如,在以下情况中:

plot(1:100); hold on; plot(-100:100,abs(-100:100))
Run Code Online (Sandbox Code Playgroud)

我希望它清楚,这里有2个图我试图简单地增加不同图的x值,但这会使数据偏差太大

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

Ste*_*eve 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');
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

-2-使用实线和破折号

正如其他人在评论中指出的那样,你可以在实线或某些样式组合上划一条虚线.

-3-使用不同的线条粗细

使用底部最厚的不同线宽:

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

在此输入图像描述

-4-每条线都使用单独的图表进行扭曲

调出每一行的另一种方法是在子图中绘制每条线,但首先以灰色绘制所有数据.通过这种方式,您可以看到调出每条特定行的所有行的位置:

在此输入图像描述

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
Run Code Online (Sandbox Code Playgroud)