![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174281/image.png)
Filling a polygon using an index and colormap
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Kenneth Morley
il 27 Gen 2014
Commentato: li linjiang
il 6 Mag 2020
I am attempting to fill in the polygons of counties based on data collected. I have attached the array I am working with. It has 61 counties. I would like to fill these counties based on the values in counties.risk. How can I do this? I have been using geoshow to show the counties up until now. Thanks so much for your help!
Kenny
0 Commenti
Risposta accettata
Rob Comer
il 29 Gen 2014
The key to making many thematic maps is to use the makesymbolspec function in combination with geoshow or mapshow . In this case, because polygons are being color-coded, it's more specifically a "choropleth map."
load ToUpload
figure('Color','white')
worldmap([20 35],[-100 -78])
colormap(summer(512))
riskSymbolSpec = makesymbolspec('Polygon', ...
{'risk',[0 40],'FaceColor',colormap});
geoshow(counties,'SymbolSpec',riskSymbolSpec)
colorbar
caxis([0 40])
set(get(colorbar,'YLabel'),'String','risk')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174281/image.png)
2 Commenti
Walter Roberson
il 7 Giu 2016
Giuliano Langella comments,
"very useful to map continuous numerical attribute!"
li linjiang
il 6 Mag 2020
When i test with my data, it is not correct. Some Polygons can not be filled. here is my code:
clear;
load mydata
figure('Color','white')
%worldmap([20 35],[-100 -78])
colormap(summer(512))
riskSymbolSpec = makesymbolspec('Polygon', ...
{'risk',[0 40],'FaceColor',colormap,'EdgeColor','g'});
geoshow(counties,'SymbolSpec',riskSymbolSpec)
colorbar
hold on
xlim([121.5 122]);
ylim([31 31.5]);
caxis([0 40])
set(get(colorbar,'YLabel'),'String','risk')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290699/image.png)
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!