MATLAB Answers

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

조회 수: 12(최근 30일)
Marina
Marina 2017년 3월 23일
댓글: Marina 2017년 5월 30일
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)

채택된 답변

Chad Greene
Chad Greene 2017년 5월 24일
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.
  댓글 수: 1
Marina
Marina 2017년 5월 30일
Hi Chad, thank you so much for the function. That's really great and helpful.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by