force colour of pixels with certain values to black when using a colormap with imagesc
40 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
DGM
on 31 Oct 2022
Edited: DGM
on 31 Oct 2022
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
More Answers (0)
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!