force colour of pixels with certain values to black when using a colormap with imagesc

조회 수: 19 (최근 30일)
Hi there,
I'm using imagesc to produce the following image (which is a plot of angular error for a given azimuth and elevation value):
Using caxis([0,10]); to constrain the range of valid values between 0 and 10 degrees is great. BUT, what I want to be able to do is assign another custom colour (e.g., white or black) to all values > 10. Can someone help me do this when plotting with imagesc?
I've tried defining a custom colourmap by setting the uppomost value to white for example, BUT, it sets all values that are 10 also to white (see below image). I need to retain those values...
So I'm looking for a way of forcing the colormap and colorbar to remain as above but only for values > 10 (the last image actually sets results = 10 also to white but I only want this for values greater than the maximum value of my colorbar), Like a thresholding operation.
Any assistance would be greatly received!
Many thanks.
Mark

채택된 답변

DGM
DGM 2022년 10월 31일
편집: DGM 2022년 10월 31일
If you're using imagesc(), image(), or imshow(), you can use the 'alphadata' property:
% we have some data that spans from 0 beyond 10
Z = peaks(100);
Z = normalize(Z,'range')*15;
% create a mask to describe regions within normal data range
alpha = Z<=10;
imagesc(Z,'alphadata',alpha)
colorbar
You can then choose the background color by setting the 'color' property of the parent axes:
set(gca,'color',[1 0.3 0.7]) % or any color you want

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by