フィルターのクリア

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 Center および File ExchangeMap Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by