필터 지우기
필터 지우기

Issue creating a map of the USA

조회 수: 6 (최근 30일)
Caleb Rudick
Caleb Rudick 2020년 12월 9일
댓글: Caleb Rudick 2020년 12월 9일
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')

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 9일
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));
  댓글 수: 1
Caleb Rudick
Caleb Rudick 2020년 12월 9일
OH MY GOSH THANK YOU SO MUCH!!!!!!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by