Why does not m_pcolor draw some colors?

3 views (last 30 days)
Szabó-Takács Beáta
Szabó-Takács Beáta on 30 Sep 2015
Edited: Image Analyst on 3 Oct 2015
Dear All, . I would like to draw my own data on Lambert Conformal Conic projected map using with m_map package. I tried the followings:
m_proj('lambert','longitude',[-34.748 60.8422],'latitude',[26.5861 71.8699]);
m_coast('patch',[1 .85 .7]);
m_pcolor(lon1,lat1,clim);
set(findobj('tag', 'm_pcolor'), 'edgecolor', 'none');
colormap(map);
>> h=colorbar;
labels={'ET'; 'BSk'; 'BWh'; 'BWk'; 'As'; 'Csa'; 'Cfa'};
h=colorbar;
set(h,'YTickMode','manual','YTick',[1:length(map)],'YTickLabelMode','manual','YTickLabel',labels);
where lon1, lat1 and clim 2D matrices (177x191), map is
m1= [101 255 255]./255;
m4= [207 170 85]./255;
m5= [255 207 0]./255;
m6= [255 255 101]./255;
m9= [255 154 154]./255;
m11= [0 254 0]./255;
m17= [0 48 0]./255;
map=[m1;
m4;
m5;
m6;
m9;
m11;
m17];
The clim matrix contains 7 values: 1, 4, 5, 6, 9, 11, 17 which have color m1, m4, m5, m6, m9, m11, m17. I attached the resulted map (Figure_sample). I do not understand why some colors are missing from the map? Could someone inform me what I did wrong?

Answers (1)

Chad Greene
Chad Greene on 1 Oct 2015
I'm not sure if this is causing your problems, but your Ytick values should be
[1, 4, 5, 6, 9, 11, 17];
not
[1:length(map)]
  2 Comments
Chad Greene
Chad Greene on 2 Oct 2015
Ah, of course! The values 1, 4, 5, 6, 9, 11, and 17 are not evenly spaced, so a colorbar linked to those values will not be evenly spaced. One way around this is to simply plot data that has evenly-spaced values. We'll call it catclim for categorical clim. The values in your clim matrix are
climvals = [1, 4, 5, 6, 9, 11, 17];
So create an empty catclim matrix:
catclim = NaN(size(clim));
And fill catclim with evenly-spaced numbers 1 through 7:
for k = 1:length(climvals)
catclim(clim==climvals(k)) = k;
end
Now plot
m_pcolor(lon1,lat1,catclim);
shading flat
cb = colorbar;
set(cb,'ytick',climvals,'yticklabel',labels)

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!