How to set a color for a certan value (without showing that value in the colorbar)?
4 views (last 30 days)
Show older comments
Marilena Geng
on 25 Mar 2016
Commented: Marilena Geng
on 30 Mar 2016
Dear community,
this is my very first post and I'm new to Matlab, I hope I'm not asking for anything very obvious.
So I'm plotting (surface) a map of Greenland. I have values ranging from 0-1 ("FI"). I just want to see the range from 0.53-0.73, which works fine with using my own colormap and: colormap(map); surface(longrid,latgrid,FI, 'EdgeColor', 'none'); caxis([0.52 0.73]); c = colorbar('Ticks',[0.53:0.02:0.73],'YColor',[0 0 0]);. But now I would like to set the sea around Greenland to the color white or blue. In my matrix (FI) the sea grids have the value zero (but I can set them to any value), so can I somehow just say: "plot zeros white" without having the white/zeros showing up in my colorbar?

Thanks a lot in advance!
0 Comments
Accepted Answer
Kelly Kearney
on 25 Mar 2016
I suggest changing the 0-values to NaNs; in a surface plot, those values aren't plotted, so the background axis color shows through instead:
FI(FI == 0) = NaN;
colormap(map);
surface(longrid,latgrid,FI, 'EdgeColor', 'none');
caxis([0.52 0.73]);
c = colorbar('Ticks',[0.53:0.02:0.73],'YColor',[0 0 0]);
set(gca, 'color', 'w'); % or whatever color you want for the background
3 Comments
Kelly Kearney
on 28 Mar 2016
How is the glacier defined? As a grid, or a polygon? If the latter, I'd make the axis background blue, draw a white patch for the glacier, then add the pcolor plot on top.
[x,y,z] = peaks(100);
z(z <= 0) = NaN; % Main data
th = linspace(0, 2*pi, 20);
xg = 2*cos(th); % The glacier as a polygon
yg = 2*sin(th);
isglac = sqrt(x.^2 + y.^2) <= 2; % The glacier as a grid
figure;
axes('color', rgb('light blue'));
hold on;
hp = pcolor(x,y,z);
shading flat;
colormap hot;
hg = patch(xg, yg, 'w', 'edgecolor', 'none');
uistack(hg, 'bottom');
(Note that I drew the patch second and moved it to the bottom because shading flat applies to all surfaces and patches in the axis, and we don't want it to affect that patch.
If it's a grid, I'd layer two axes on top of each other, with different colormaps, and make the top axis invisible:
figure;
ax(1) = axes;
hg = pcolor(ax(1), x,y,double(isglac));
shading flat;
colormap(ax(1), [rgb('light blue'); rgb('white')]);
ax(2) = axes('position', ax(1).Position);
hg = pcolor(ax(2), x,y,z);
shading flat;
colormap(ax(2), hot);
set(ax(2), 'visible', 'off');
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!