Scatter plot with different color for points above the linear fit line

조회 수: 5 (최근 30일)
MatLab Code N
MatLab Code N 2020년 6월 4일
답변: Tommy 2020년 6월 4일
Hi,
In my regression analysis I am geting two different lobes of data. I want to get different color for points above the regression line in the scatter plot and know their positions.
Thanks!

채택된 답변

Tommy
Tommy 2020년 6월 4일
Here's a simple example using a linear regression, hopefully you find it helpful:
% random data
X = rand(100,1);
Y = 0.5*X + rand(100,1);
% linear regression
b = [ones(numel(X),1), X]\Y;
Yfit = b(2)*X + b(1); % Y(i) and Yfit(i) are located at same x value
% compare corresponding points in y direction
idx = Y > Yfit; % idx(i) tells whether Y(i) is above Yfit(i)
% plot
scatter(X(idx),Y(idx),'r');
hold on;
scatter(X(~idx),Y(~idx),'b');
plot(X,Yfit,'k');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Regression에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by