How to add simple rectangle legend inside US map?
조회 수: 3 (최근 30일)
이전 댓글 표시
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])
댓글 수: 0
답변 (1개)
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:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!