Plot raster map with custom colormap
Show older comments
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.
Answers (3)
Sam
on 12 Jan 2016
Chad Greene
on 12 Jan 2016
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 Comments
Mahmoud Solomon
on 10 Jun 2018
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
on 21 Jun 2018
Walter Roberson
on 10 Jun 2018
0 votes
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 Comment
Mahmoud Solomon
on 11 Jun 2018
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.
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!