How to set a color for a certan value (without showing that value in the colorbar)?

조회 수: 3 (최근 30일)
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!

채택된 답변

Kelly Kearney
Kelly Kearney 2016년 3월 25일
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
Kelly Kearney
Kelly Kearney 2016년 3월 28일
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');
Marilena Geng
Marilena Geng 2016년 3월 30일
Awesome! It's a grid and the second options works perfectly :) Thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by