Plot raster map with custom colormap
显示 更早的评论
I have a matrix map_data associated with referencing object R (both in attached MAT-file). I want to map it with a discrete colorbar given an irregular range of values to look something like this:

How can I do this using geoshow or something else?
I'm using MATLAB r2014b. Here is the relevant information for the colormap:
R G B
0 <= map_data < 0.001 204 204 204
0.001 <= map_data < 0.005 153 153 153
0.005 <= map_data < 0.01 255 255 178
0.01 <= map_data < 0.05 254 204 92
0.05 <= map_data < 0.1 253 141 60
0.1 <= map_data < 0.25 240 59 32
0.25 <= map_data < 0.5 189 0 38
0.5 <= map_data < 1 0 0 0
Thanks in advance.
回答(3 个)
Chad Greene
2016-1-12
I take philosophical issue with binning values from a continuous range unless those exact bins are used as discrete categories for your work. I don't know anything about the application, but as a general rule of thumb I say let continuous variables be depicted by continuous colormaps. Perhaps plot in log scale? Here's my stab at it. I couldn't load your referencing matrix R so I made up a grid that seems approximately right. Below I'm using Stephen Cobeldick's brewermap function and my rgb function to define colors.
% Load data:
load 'matlab_20160111.mat';
% Initialize map:
worldmap('world')
geoshow('landareas.shp','facecolor',0.8*[1 1 1])
% Plot gridded data:
[lon,lat] = meshgrid(-179:2.5:179,-89:2:89);
pcolorm(lat,lon,log10(100*map_data));
% Set colorbar with log10 scale:
caxis([0 2])
cb = colorbar;
set(cb,'ytick',log10([1 5 10 50 100]),...
'yticklabel',num2str([1 5 10 50 100]'))
ylabel(cb,'percentage of some variable')
% Define colormap and background color:
colormap(brewermap(256,'reds'))
setm(gca,'ffacecolor',rgb('ocean blue'))

2 个评论
Mahmoud Solomon
2018-6-10
I followed this procedure and was able to generate this map. However, I have tried manipulating the code to plot only for specific region but this has not work. Can you please help me out?
Chad Greene
2018-6-21
Walter Roberson
2018-6-10
0 个投票
See https://www.mathworks.com/matlabcentral/answers/377542-how-can-i-change-number-on-colorbar-caxis#answer_300478 to see how to create a colormap with the desired properties without binning the data itself.
1 个评论
Mahmoud Solomon
2018-6-11
Thanks for your response but I was talking about the plot itself and not the colorbar. I want to plot on the map but for a specific region and not the entire map.
类别
在 帮助中心 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
