How to generate a map of European countries coloured according to a vector of positive and negative values?
Show older comments
Hello all,
I am trying to get a map of the European countries (cou_nam) in which the color of each country is assigned according to a vector including 0, positive and negative values (data).
The approach I follow is based on both the Mapping Toolbox as well as the borders file exchange submission.
% country names
cou_nam = {'Belgium', 'Bulgaria', 'Czech Republic', 'Denmark', 'Germany','Estonia','Ireland',...
'Greece','Spain','France','Croatia','Italy', 'Cyprus','Latvia', 'Lithuania', 'Luxembourg',...
'Hungary', 'Malta', 'Netherlands','Austria', 'Poland', 'Portugal','Romania','Slovenia', 'Slovakia',...
'Finland', 'Sweden'};
numRegions = length(cou_nam);
cmap = colormap;
% Random vector of values (one for each country)
data = randi([-5,5],numRegions,1);
% Map
figure('Color','w')
xh = worldmap('Europe');
setm(xh,'MapProjection','miller')
tightmap
geoshow ('landareas.shp', 'FaceColor', 'white');
for i = 1:1:numRegions
bordersm(cou_nam{i},'facecolor',cmap(data(i),:)) % => problem with negative values
end
colorbar
The issue with this code is that the variable data stores both negative and positive values, so when called in the for loop gets back an error since only positive integers are accepted.
Also, if I insert only positive values, i.e.
data = randi([1,5],numRegions,1);
it seems that the colorbar doesn't conform with the range of the values in data.
I have seen that there are similar questions (here and here) in the Community, yet I have not managed to get a solution.
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on White 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!
