Change colors of pcolor meeting spesific conditions

조회 수: 9 (최근 30일)
Abdul Kadir Alhamid
Abdul Kadir Alhamid 2020년 7월 25일
댓글: Abdul Kadir Alhamid 2020년 7월 25일
Hi there
I have a 810x810 elevation data matrix (le's say Z). I want to plot it using pcolor with
colormap(winter(10))
However, for every Z <= 0, I want to change the color into one ocean blue or just plain red. Does anyone know how to do this?
Thanks.
Abdul

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 25일
cmap = winter(10));
cmap(1,:) = [.7 0 0]; %plain red
Ztemp = max(0, Z);
pcolor(X, Y, Ztemp);
colormap(cmap)
When you use pcolor(), the Z coordinates are all set to 0, not to the value of the data, so it does not matter that your Z is not the "correct" Z, you won't be able to tell with datatips (not unless you use a custom datatip function.)
There are alternatives to pcolor() that do not set the Z to all 0, and for those alternative functions, it can be a bit tricky to arrange that all negative values are one color without affecting the correct functioning of the Z coordinate in datatips.
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 7월 25일
Note that for the above FEX contribution, the value parameter is relative values, 0 to 1, not absolute values. You would use
(input_actual_value - minumum_value) ./ (maximum_value - minimum_value)
to get the proportions. If you prefer, you can use function rescale() with 'InputMin' and 'InputMax' options; or use the badly-named mat2gray() function if you have an older MATLAB release.
This is only needed to get the values to create the map. When you plot the data, use caxis() to set the upper and lower bounds of the data, to get consistent mapping to the colors.
Abdul Kadir Alhamid
Abdul Kadir Alhamid 2020년 7월 25일
Thank you very much!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by