create specific color map and save it

조회 수: 2 (최근 30일)
Sajid Afaque
Sajid Afaque 2020년 5월 28일
댓글: Ameer Hamza 2020년 5월 28일
how do i create my own color map for 2D-scatter plot.
such that all the values of z
  1. z <= 10 ------- take green color
  2. 10 < z <= 25 ----- yellow color
  3. 25 < z <= 50 ----- orange color
  4. z > 50 ----- red color
i want to create a color map obeying such condition and save it , so that i can use with whatever z i obtain in future.
as an example i have attached x,y,z
scatter(x,y,[],z,'filled','o')
  댓글 수: 1
KSSV
KSSV 2020년 5월 28일
Same question you have asked multiple times...

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 28일
Try this
val_z = (10:51).';
idx = 1*(val_z<=10) + ...
2*((10<val_z) & (val_z<=25)) + ...
3*((25<val_z) & (val_z<=50)) + ...
4*(val_z>50);
colors = [0 1 0; % green
1 1 0; % yellow
1 0.5 0; % orange
1 0 0]; % red
cmap = colors(idx, :);
scatter(x,y,[],z,'filled','o')
colormap(cmap)
set(gca, 'CLim', [10 51]);
  댓글 수: 12
Sajid Afaque
Sajid Afaque 2020년 5월 28일
yeah color ranges are ok ,only colorbar gets repeated after certain interval.
do you have any idea why this may be.
thank you for your help .
much appreciated
Ameer Hamza
Ameer Hamza 2020년 5월 28일
I don't have any idea about this. Maybe something is mentioned in archived documentation, but the reason is not obvious.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by