- 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?
18 次查看(过去 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!