Assigning black color to zero values of "imagesc" plot
47 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Image Analyst
el 24 de Sept. de 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 comentarios
Image Analyst
el 25 de Sept. de 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
Más respuestas (1)
Kelly Kearney
el 24 de Sept. de 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 comentarios
Kelly Kearney
el 25 de Sept. de 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;
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!