Clear Filters
Clear Filters

Map of data by country

52 views (last 30 days)
Brendan Clark
Brendan Clark on 13 Sep 2021
Answered: ag on 13 Oct 2023
I have a table with two columns. One is the name of all countries on Earth, the other is a corresponding numeric value. I would like to make a world map with each countries individual face color representing that value. I will attach an example of what I mean. Is there a way to do this?
  3 Comments
Star Strider
Star Strider on 13 Sep 2021
I don’t have the Mapping Toolbox, however I experimented with it in the online Run application, that does. There may be a shape file that defines the country borders as polygons, however if it exists, its existence doesn’t appear to be documented.
.
Dave B
Dave B on 14 Sep 2021
It might be worth checking out the borders submission on file exchange, which can do this sort of thing though it might be a little slow to show all countries: https://www.mathworks.com/matlabcentral/fileexchange/50390-borders

Sign in to comment.

Answers (1)

ag
ag on 13 Oct 2023
Hi Brendan,
I understand that you need to make a world map, with individual face colours for each country.
You can explore the “Natural Earth Data” website to get the required data, and then refer the below code, to get a broad idea on how to go ahead with your task,
world = shaperead('ne_110m_land.shp')
world.BoundingBox
figure;
ax = axes;
col = string({'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black', 'white', 'none'})
for i = 1:numel(world)
country = world(i);
value = randperm(80,1);
% Set the face color based on the value
v = mod(value(1),8)+1;
disp(col(v))
faceColor = col(v);
% Plot the country with the specified face color
geoshow(ax, country, 'FaceColor', faceColor);
hold on;
end
colorbar;
Please refer to the following resources for more details:
Hope this helps!
Best Regards,
Aryan Gupta

Community Treasure Hunt

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

Start Hunting!