How to add simple rectangle legend inside US map?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/238698/Capture.png)
0 Commenti
Risposte (1)
Vahila Kayithi
il 26 Dic 2019
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 Commenti
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!