- You can add more subsets.
- You can update details on which state should belong to which subset.
- You can also assign different colours to each subset.
How to create USA map with states names having different colors?
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi,
I want to generate the USA map as follows with the help of mapping toolbox. It should include the Alaska and Hawai. Ans also be able to give the different color based on data and customized number as shown here.
댓글 수: 0
답변 (1개)
Asvin Kumar
2021년 3월 18일
usamap is the function you're looking for. Have a look at the example on diplaying the map of USA including Alaska and Hawaii.
Here's an updated version of the code from the example:
% Map the USA Including Alaska and Hawaii
% Map the USA with separate axes for Alaska and Hawaii.
figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
% Indices
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
statesSubset1 = {'Illinois', 'Texas'}; % Edit this list
indices = cellfun(@(x) strcmp(x,names), statesSubset1, 'UniformOutput', false);
indicesSubset1 = indices{1};
for i = 2:numel(indices)
indicesSubset1 = indicesSubset1 | indices{i} ;
end
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska|indicesSubset1) = [];
% Colours
stateColor1 = [0.5 1 0.5]; % Edit colours as needed
stateColor2 = [1 0 0];
stateColor3 = [0 0 1];
% Display the three regions.
geoshow(ax(1), states(indexConus), 'FaceColor', stateColor1)
geoshow(ax(1), states(indicesSubset1), 'FaceColor', stateColor2)
geoshow(ax(2), states(indexAlaska), 'FaceColor', stateColor3)
geoshow(ax(3), states(indexHawaii), 'FaceColor', stateColor3)
%Hide the frame.
for k = 1:3
setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
'ParallelLabel', 'off', 'MeridianLabel', 'off')
end
You should be able to adapt this code to your use case.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!