Mapshow : attribute colors to polygons according to ID

2 ビュー (過去 30 日間)
Loriann Chevalier
Loriann Chevalier 2022 年 8 月 25 日
コメント済み: Loriann Chevalier 2022 年 8 月 26 日
Hi everyone,
I have the map layer of climate zones downloaded from there : https://datacatalog.worldbank.org/search/dataset/0042325
I would like to display the different climate zones of Ethiopia, and represent each climate zone according to the climate type (GRIDCODE field in my shapefile's structure). I have this so far :
addpath('...')
climate = shaperead('c1976_2000.shp');
figure();
set(groot,'defaultLineMarkerSize',6);
mapshow(climate, "DefaultEdgeColor",[0.9 0.9 0.9])
xlim([32 49]);
ylim([2 16]);
The map displays fine and for my region of interest. However all the climate zones just appear in yellow. Obviously I would like to have them appear each in a different color according to their GRIDCODE ID but I can't do that and couldn't find anything on MathWorks either.
Thanks!

採用された回答

Chad Greene
Chad Greene 2022 年 8 月 25 日
Try this. Define a list of colors, and plot each gridcode region seperately.
climate = shaperead('c1976_2000.shp');
% List of grid codes:
gc = [climate.GRIDCODE];
% What are the unique values of grid codes?
ugc = unique(gc);
% A color for each unique grid code:
col = parula(length(ugc));
figure()
hold on
% Loop through each unique gridcode:
for k = 1:length(ugc)
% Plot only the shapes that whose grid code is ugc(k)
mapshow(climate(gc==ugc(k)), "DefaultEdgeColor",[0.9 0.9 0.9],'facecolor',col(k,:))
end
  1 件のコメント
Loriann Chevalier
Loriann Chevalier 2022 年 8 月 26 日
Thank you so much ! Works perfectly

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClimate Science and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by