How to fill polygons based on attribute values?

16 ビュー (過去 30 日間)
Keegan Carvalho
Keegan Carvalho 2022 年 6 月 23 日
編集済み: Keegan Carvalho 2022 年 6 月 24 日
I have used the following code to load and plot the shapefile "Expot.shp" (attaced zip file). I wanted to plot the "Corr" attribute, but for some reason the colour does not match the values. (Also, the "Corr" values with zeros are basically not calculated - can treat them as NaNs)
landAreas = readgeotable("landareas.shp"); %from "geoshow" matlab documentation
row = landAreas.Name == "North and South America";
landAreasSubset = landAreas(row,:);
corr = shaperead("Expot.shp")
cmap = jet(256);
colorRange = makesymbolspec("Polygon", ...
{'Corr',[-0.02 0.05],'FaceColor',cmap}); %Use makesymbolspec to specify polygon colors
mapshow(corr,"SymbolSpec",colorRange)
colormap(cmap)
caxis([-0.02 0.05])
colorbar
hold on
geoshow(landAreasSubset)
The result map is attached below
The legend shows the "Corr" values but the map does not. I'd like to know where I seem to be going wrong; I think there's a line of code missing or needs to be changed.
I'd be grateful for assistance on this. Thank You

採用された回答

KSSV
KSSV 2022 年 6 月 23 日
編集済み: KSSV 2022 年 6 月 23 日
How about this?
shpFile = 'Expot.shp' ;
S = shaperead(shpFile) ;
N = length(S) ;
cmap = jet(N) ;
figure
hold on
for i = 1:N
x = S(i).X ; y = S(i).Y ;
x(isnan(x))=[] ;
y(isnan(y))=[] ;
patch(x,y,cmap(i,:)) ;
end
colorbar
colormap(cmap)
  11 件のコメント
KSSV
KSSV 2022 年 6 月 23 日
This is the correct mapping of corr right?
Keegan Carvalho
Keegan Carvalho 2022 年 6 月 24 日
編集済み: Keegan Carvalho 2022 年 6 月 24 日
Not quite. The regions with values "0", I prefer not having a colour for them, becasue they are essentially "NaN" values. Is there a way to code to show no colour for the polygons with "0" values?
If the regions with "0" show no color, then I can determine if it is correct. Because most of the polygons with "0" show different colours in the above map

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by