Azzera filtri
Azzera filtri

Issue creating a map of the USA

6 visualizzazioni (ultimi 30 giorni)
Caleb Rudick
Caleb Rudick il 9 Dic 2020
Commentato: Caleb Rudick il 9 Dic 2020
I've been trying to figure out how to create a map of the USA (including Alaska and Hawaii) with labels for every state using the usamap function. Matlab only has documentation for how to name specific regions, not the whole country. My code is below - would anybody be able to help me modify it so that I can label the states? Thank you!!!!!!!
% Create a map of the continental United States
figure;
electionMap = usamap('all');
states = shaperead('usastatehi','UseGeoCoords',true);
nameStates = {states.Name};
Conus = 1:numel(states);
Alaska = strcmp(nameStates,'Alaska');
Hawaii = strcmp(nameStates,'Hawaii');
Conus(Hawaii|Alaska) = [];
% Display and format map of US mainland and Alaska and Hawaii
setm(electionMap(1),'Frame','off','Grid','off','MeridianLabel','off','ParallelLabel','off')
geoshow(electionMap(1),states(Conus),'FaceColor','#F6E8B1')
setm(electionMap(2),'Frame','off','Grid','off','MeridianLabel','off','ParallelLabel','off')
geoshow(electionMap(2), states(Alaska),'FaceColor','#F6E8B1')
setm(electionMap(3),'Frame','off','Grid','off','MeridianLabel','off','ParallelLabel','off')
geoshow(electionMap(3), states(Hawaii),'FaceColor','#F6E8B1')

Risposta accettata

Cris LaPierre
Cris LaPierre il 9 Dic 2020
You can see an example here.
figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = [];
stateColor = [0.5 1 0.5];
Display the three regions.
geoshow(ax(1), states(indexConus), 'FaceColor', stateColor)
geoshow(ax(2), states(indexAlaska), 'FaceColor', stateColor)
geoshow(ax(3), states(indexHawaii), 'FaceColor', stateColor)
Hide the frame.
for k = 1:3
setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
'ParallelLabel', 'off', 'MeridianLabel', 'off')
end
Add labels to each state.
lat = [states(indexConus).LabelLat];
lon = [states(indexConus).LabelLon];
textm(lat, lon, {states(indexConus).Name},'HorizontalAlignment', 'center','Parent',ax(1));
latA = [states(indexAlaska).LabelLat];
lonA = [states(indexAlaska).LabelLon];
textm(latA, lonA, {states(indexAlaska).Name},'HorizontalAlignment', 'center','Parent',ax(2));
latH = [states(indexHawaii).LabelLat];
lonH = [states(indexHawaii).LabelLon];
textm(latH, lonH, {states(indexHawaii).Name},'HorizontalAlignment', 'center','Parent',ax(3));

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by