Assigning black color to zero values of "imagesc" plot
47 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to use "imagesc" to plot the following matrix:
A=[9 24 6 12 6;
0 33 24 0 12;
0 0 13 14 12;
0 0 0 0 0];
I want to assign black color to 0 values and set the color bar from 6 to 33.
0 commentaires
Réponse acceptée
Image Analyst
le 24 Sep 2013
Try this:
A=[9 24 6 12 6;
0 33 24 0 12;
0 0 13 14 12;
0 0 0 0 0];
imagesc(A);
cmap = jet(max(A(:)));
% Make values 0-5 black:
cmap(1:6,:) = zeros(6,3);
colormap(cmap);
colorbar
2 commentaires
Image Analyst
le 25 Sep 2013
A=[9 9.1 8.3 0 0;
0 9.5 8.4 0 0;
0 0 9.6 8.3 8.1;
0 0 0 9.7 0];
lowestValue = min(A(A(:)>0))
highestValue = max(A(:))
imagesc(A);
cmap = jet(256);
colormap(cmap);
caxis(gca,[lowestValue-2/256, highestValue]);
% Make less than lowest value black:
cmap(1,:)=[0,0,0];
colormap(cmap)
colorbar
Plus de réponses (1)
Kelly Kearney
le 24 Sep 2013
It'll be a little tricky to do with imagesc, but you could get a similar result with pcolor:
aplt = nan(size(A)+1);
aplt(1:end-1,1:end-1) = A;
aplt(aplt == 0) = NaN;
pcolor(aplt);
colorbar;
set(gca, 'color', 'k', 'clim', [6 33], 'ydir', 'reverse')
2 commentaires
Kelly Kearney
le 25 Sep 2013
Neither function does any smoothing, unless you use interpolated shading with the pcolor plot. If you're referring to the black outlines of each grid cell that is the default under pcolor, you can alter that with a simple
shading flat;
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!