imagesc make all negatives values black
3 views (last 30 days)
Show older comments
I have the following code which is part of a subplot series. I want to change it so that all negative values become a certain colour (preferably black). I am stuck as to how to achieve this.
figure(3)
subplot(3,3,1)
imagesc(coeffA40)
title ('A40 Coefficients')
caxis([minCoeff, maxCoeff])
myColorMap = hsv(256);
myColorMap(1,:) = 1;
colormap(myColorMap);
grid on
ax = gca
ax.LineWidth = .75
ax.GridColor = 'k'
ax.GridAlpha = .2
ax.XTick = [10 20 30 40];
ax.YTick = [10 20 30];
ax.XTickLabel = {'', '', '', ''};
ax.YTickLabel = {'','',''};
ax.TickLength =[0.0 0.0]
ax.XTickLabelRotation = 45
Thank you in advance for any help!
0 Comments
Answers (1)
Image Analyst
on 29 Mar 2016
Several ways. One is to create a temporary image
displayedImage = coeffA40; % Initialize
displayedImage(displayedImage <=0) = 0;
cmap = jet(256);
cmap(1,:) = 0; % Lowest gray level appears black.
imshow(displayedImage);
colormap(cmap);
colorbar;
Another might be to alter the colormap so that it applies between 0 and the max.
cmap = jet(256);
cmap(1,:) = 0; % Lowest gray level appears black.
imshow(coeffA40);
colormap(cmap);
colorbar;
caxis([0, max(coeffA40(:))]);
(Both of these are untested - just off the top of my head.)
3 Comments
Image Analyst
on 29 Mar 2016
Set the nans to the max value (or the white value) before display, something like:
displayedImage(isnan(displayedImage)) = max(displayedImage(:));
Walter Roberson
on 29 Mar 2016
image(coeffA40, 'AlphaData', double(~isnan(coeffA40)) )
See Also
Categories
Find more on Orange in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!