フィルターのクリア

How to add simple rectangle legend inside US map?

6 ビュー (過去 30 日間)
Chanik Jo
Chanik Jo 2019 年 9 月 18 日
回答済み: Vahila Kayithi 2019 年 12 月 26 日
Hi all,
I'd like to add a simple legend with two rectangles like the following inside the US map (rectangle No shock, another rectangle with different color Shock)
Did anyone know?
Here is my current code.
clear all; clc;
states = shaperead('usastatehi', 'UseGeoCoords', true);
statenames = {states.Name};
alaska = states(strcmp('Alaska', statenames));
hawaii = states(strcmp('Hawaii', statenames));
f = figure;
hconus = usamap('conus');
for i = 1:51
ccolor = [1 1 1];
geoshow(hconus, states(i), 'FaceColor', ccolor)
end
framem off; gridm off; mlabel off; plabel off
halaska = axes('Parent',f);
usamap('alaska')
geoshow(alaska, 'FaceColor', [0.23 0.44 0.67]);
framem off; gridm off; mlabel off; plabel off
hhawaii = axes('Parent',f);
usamap('hawaii')
geoshow(hawaii, 'FaceColor', [1 1 1]);
framem off; gridm off; mlabel off; plabel off
set(hconus, 'Position',[0.1 0.35 0.85 0.6])
set(halaska,'Position',[0.2 0.42 0.2 0.2])
set(hhawaii,'Position',[0.25 0.43 0.2 0.2])
Capture.PNG

回答 (1 件)

Vahila Kayithi
Vahila Kayithi 2019 年 12 月 26 日
The rectangular legend can be obtained by changing the 'Display Type' property. Create the handles for 'geoshow' and change the 'Display Type' property. Pass the handles to legends.
h(1) = geoshow(alaska, 'FaceColor', [0.23 0.44 0.67],'DisplayType', 'polygon');
h(2) = geoshow(hawaii, 'FaceColor', [0 0 0],'DisplayType', 'polygon') ;
legend([h(1),h(2)],'No Shock','Shock');
For more information, please refer:

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by