필터 지우기
필터 지우기

How do I make a red and blue colormap?

조회 수: 116 (최근 30일)
L'O.G.
L'O.G. 2022년 9월 15일
댓글: Star Strider 2022년 9월 15일
I can plot a matrix of integers using imagesc. How do I make a discrete colormap (i.e., only for the integers) with a gradient of red colors for positive values and a gradient of blue colors for negative values, with zero being white? Also, the numbers aren't symmetric about zero, i.e., they range from [-2,5] so I want a deep blue for -2 and a deep red for 5. I hope that makes sense.

채택된 답변

Star Strider
Star Strider 2022년 9월 15일
I am not exactly certain what you want, however the basic colormap is easy to create —
cm = [1 0 0; 1 1 1; 0 0 1]; % Basic Colormap
cmi = interp1([-2; 0; 5], cm, (-2:5)) % interpolated Colormap
cmi = 8×3
1.0000 0 0 1.0000 0.5000 0.5000 1.0000 1.0000 1.0000 0.8000 0.8000 1.0000 0.6000 0.6000 1.0000 0.4000 0.4000 1.0000 0.2000 0.2000 1.0000 0 0 1.0000
M = randi([-2 5],9) % Matrix
M = 9×9
-1 5 3 -2 -1 -2 3 2 3 1 1 -2 1 0 4 -2 1 -2 2 0 5 -1 4 -1 2 -2 0 0 2 0 -1 5 -1 -2 4 1 -2 1 1 3 -2 4 -1 -1 1 2 1 4 4 0 1 5 1 3 5 0 4 1 4 3 -2 4 -2 -2 4 -2 1 1 3 4 1 -2 5 4 5 4 -2 3 2 -2 0
figure
imagesc(M)
colormap(cmi)
Experiment to get different results.
.
  댓글 수: 2
L'O.G.
L'O.G. 2022년 9월 15일
Thank you!
Star Strider
Star Strider 2022년 9월 15일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by