Connect line in scatter plot without jump

조회 수: 9 (최근 30일)
Haining Pan
Haining Pan 2019년 2월 25일
댓글: darova 2019년 10월 31일
Is there is elegant way to connect the line between the nearest points in scatter plot?
The reason I ask is because ```plot``` will connect the line based on the 'index of row' of Y(data). Basically, it connects points in the same row in Y. However, this sometimes will result in a jump, which is due to the missing data in one row( and thus all the following data will all mislabeled and shifted by 1, and this cannot be avoided for some practical reason).
Here is a minimal example of the problem.
xrange=linspace(-2,2,100);
Y=repmat(-xrange.^2,4,1)+repmat((-4:-1)',1,100);
Y(Y<-5)=0;
for i=1:100
[~,~,v]=find(Y(:,i));
Y(1:length(v),i)=v;
end
Y(Y==0)=nan;
%jump due to missing data
figure;
plot(xrange,Y);
figure;
%from bare eye, we see there are four lines
for i=1:4
scatter(xrange,Y(i,:),'b');
hold on
end
The undesirable result by using ```plot``` is:
plot.png
The jump is due to the missing data and this is unavoidable in practice.
However, we can see that there are actually four lines, by bare eyes, if we use ```scatter```.scatter.png
So what I want to achieve is to connect the nearest points but without introducing discontinuity given a imperfect data set, which is missing some data. What I can come up with is to preprocess the data before plotting but this is not always possible, because of the complicated experimental situation, which is hard to predict which data point will be missing in advance.
Any comments and answers are highly appreciated!
  댓글 수: 2
Articat
Articat 2019년 10월 31일
Currently dealing with this same issue, did you ever find a way to solve it?
darova
darova 2019년 10월 31일
Try clusterdata and k-means

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by