force colour of pixels with certain values to black when using a colormap with imagesc
14 次查看(过去 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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1174463/image.png)
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...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1174468/image.png)
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 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!