停止Matlab线图重叠 [英] stop matlab line plots from overlapping

查看:373
本文介绍了停止Matlab线图重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用plothold on绘制了多条线 但是,如果其中一条线落在另一条线上,我希望其中的一条线可以移动一点. 例如在以下情况下:

I plot many lines on top of one another, using plot and hold on however i want one of the lines to be shifted a bit if it falls on another line. for example in the following case:

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

我希望清楚这里有2个地块 我只是尝试为不同的图简单地增加x值,但这会使数据过多扭曲

i want it to be clear that there are 2 plots here i tried to simply increase x values for different plots but this skews the data too much

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

推荐答案

您可以通过几种方式区分曲线:

You can differentiate the curves in several ways:

-1-倾斜数据

如您所说,您可以稍微移动数据.我建议您固定轴,然后计算线宽的单位是多少,这样您就可以实现非常紧密的配合,

As you said, you could shift the data a bit. I would suggest fixing your axis and then calculating how many units in linewidth is so you get a very tight fit, like this:

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');

结果:

-2-使用实线和虚线

正如其他人在评论中指出的那样,您可以在实线上方使用虚线,也可以将样式进行某种组合.

As someone else noted in the comments, you could you a dashed line over a solid line, or some combination of styles.

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

使用不同的线宽,底部最粗:

Use different line widths with the thickest on the bottom:

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

-4-对每条线使用单独的图线并进行扭曲

标注每条线的另一种方法是在子图中绘制每条线,但首先将所有数据绘制成灰色.这样,您可以看到所有行都在哪里,每条特定行都被调出:

Another way to call out each line is to plot each line in a subplot but to plot all the data in gray first. This way you can see where all the lines are with each particular line called out:

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

这篇关于停止Matlab线图重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆