How can I create a graduate colour map in Matlab using the Mapping Toolbox?

4 views (last 30 days)
I'm trying to create a graduate color map in Matlab, plotting emissions (stored in a Matrix) for a couple of countries (Peru, Germany, UK,...):
To create a worldmap I used 'borders'.
screensize = get(0,'screensize');
winsize = screensize./[1 1 1 1] + [+screensize(3)/4 0 -screensize(3)/4 0];
winsize_save = [60 80 winsize(3)-80 winsize(4)-130];
% Creating own colormap, use as colormap(map)
set(fig2,'color',[1 1 1]); % for white background
whitebg([1 1 1]); % for white background
clf;
set(fig2,'color',[1 1 1]); % for white background
set(fig2,'position',winsize);
hold on
borders;
set(gcf,'color','w');
h = borders;
set(h,'color','k');
hold on
out = borders('antarctica','Color','[0.4 , 0.4 , 0.4]');
axesm robinson; mlabel('off'); plabel('off')
Now I want the countries mentioned above to be filled with color depending on the amount of calculated emissions. But I'm stuck with assigning the countries in my map with the calculated emissions. So far I tried to do it manually, by creating my own colorbar, then used 'facecolor' to fill the country with a colour representing the amount of emissions (see code below). But I'm sure there must be a nicer way to do it.
screensize = get(0,'screensize');
winsize = screensize./[1 1 1 1] + [+screensize(3)/4 0 -screensize(3)/4 0];
winsize_save = [60 80 winsize(3)-80 winsize(4)-130];
fig2 = figure(2);
% Creating own colormap, use as colormap(map)
map = zeros(5,3);
map(5,:) = [0.18 0.09 0.44];
map(4,:) = [0.06 0.13 0.97];
map(3,:) = [0.13 0.45 1.00];
map(2,:) = [0.25 0.65 0.99];
map(1,:) = [0.52 0.82 0.96];
colormap(map)
%set(fig2,'MenuBar','none','ToolBar','none');
set(fig2,'color',[1 1 1]); % for white background
whitebg([1 1 1]); % for white background
clf;
set(fig2,'color',[1 1 1]); % for white background
set(fig2,'position',winsize);
hold on
borders;
set(gcf,'color','w');
h = borders;
set(h,'color','k');
hold on
out = borders('antarctica','Color','[0.4 , 0.4 , 0.4]');
out2 = borders('United Kingdom','facecolor','[0.52 0.82 0.96]');
out3 = borders('Peru','facecolor','[0.25 0.65 0.99]');
out4 = borders('Italy','facecolor','[0.25 0.65 0.99]');
out5 = borders('France','facecolor','[0.25 0.65 0.99]');
out6 = borders('Germany','facecolor','[0.25 0.65 0.99]');
axesm robinson; mlabel('off'); plabel('off')
hcb=colorbar;
set(hcb,'YTick',[0, 0.2, 0.4, 0.6, 0.8, 1])
My questions are: 1) How can I assign countries (patch) with my emissions calculated 2) How can I fill the colour lines according to the amount of emissions (dark color - high emissions, light color - low emission)

Accepted Answer

Chad Greene
Chad Greene on 24 May 2017
Hi Marina,
You may have solved the issue by now, but I've just uploaded a function to File Exchange called patchsc. It scales patch face colors to numeric values. I haven't made a version for the Mapping Toolbox, but you may be able to tweak patchsc for use with the Mapping Toolbox.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!