change color scheme of a scatter plot

조회 수: 24 (최근 30일)
Sajid Afaque
Sajid Afaque 2020년 5월 27일
편집: KSSV 2022년 6월 16일
here above you can see i have a 2-D Scatter plot. now i want to change the color scheme.
for all the values
  1. values <= 10 ----- green color
  2. (10<values<=20) ----- yellow color (for intermediate values i.e for 13 or 16 let yellow shades become darker and similar for all 4 ranges)
  3. (20 < values <= 50) ----- orange color
  4. (50 < values ) ---- red color.

채택된 답변

Image Analyst
Image Analyst 2020년 5월 28일
Try this:
% values <= 10 ----- green color
% (10<values<=20) ----- yellow color (for intermediate values i.e for 13 or 16 let yellow shades become darker and similar for all 4 ranges)
% (20 < values <= 50) ----- orange color
% (50 < values ) ---- red color.
% First we need to create sample data because the original poster did not include it.
X = 8 : 2 : 16;
Y = 8 : 2 : 14;
[x, y] = meshgrid(X, Y);
x = x(:); % Make into 1-D vector.
y = y(:); % Make into 1-D vector.
z = randi(70, length(x), 1);
% Now we have our data and we can begin.
% We need to make up a colormap for the markers based on the value of z.
markerColors = zeros(length(x), 3);
rows = z <= 10;
markerColors(rows, :) = repmat([0, 1, 0], sum(rows), 1); % Green
rows = z > 10 & z <= 20;
markerColors(rows, :) = repmat([1, 1, 0], sum(rows), 1); % Yellow
rows = z > 20 & z <= 50;
markerColors(rows, :) = repmat([1, 0.59, 0], sum(rows), 1); % Orange
rows = z > 50;
markerColors(rows, :) = repmat([1, 0, 0], sum(rows), 1); % Red
scatter(x, y, 300, markerColors, 'filled');
grid on;

추가 답변 (2개)

KSSV
KSSV 2020년 5월 27일
You should follow like this demo:
n = 100 ;
x = 1:n ;
y = rand(size(x)) ;
% divide based on values
idx1 = y >=0 & y<0.25 ;
idx2 = y >=0.25 & y<0.5 ;
idx3 = y >=0.5 & y<0.75 ;
idx4 = y >=0.75 & y < 1 ;
figure
hold on
plot(x(idx1),y(idx1),'*r')
plot(x(idx2),y(idx2),'*b')
plot(x(idx3),y(idx3),'*g')
plot(x(idx4),y(idx4),'*k')
  댓글 수: 5
darova
darova 2020년 5월 28일
What kind of explanation do you need?
Sajid Afaque
Sajid Afaque 2020년 5월 29일
i figured it out , thank you

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


Pamudu Ranasinghe
Pamudu Ranasinghe 2022년 6월 16일
편집: KSSV 2022년 6월 16일

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by