Why does not m_pcolor draw some colors?
1 次查看(过去 30 天)
显示 更早的评论
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149577/image.jpeg)
0 个评论
回答(1 个)
Chad Greene
2015-10-1
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 个评论
Chad Greene
2015-10-2
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mapping Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!