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

40 次查看(过去 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 中查找有关 Orange 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by