How do I make a legend for my geoshow function?
9 views (last 30 days)
Show older comments
Hello,
I've never used MATLAB's create a map feature before. Matter of fact, I just found out MATLAB could even do that today!
Anyways, I'm trying to make a map for my class,and I'm able to create a map of the state of Arizona. Now I would like to add "markers" onto my map of Arizona to represent different forms of renewable energy. So an empty circle can represent solar, diamond can be water and so on. I found a code that I used tha created a marker, but it's a default + sign. How do I change that? Whenever I tried to do 'o' or 'd' I get an error.
Also, I'd like to create a legend for my map as well that says this symbol represents this source. So for my + I have on the map, how would I create a legend that says + = solar ?
I really have no expierence with this. I've included what I have so far below.
Thank you!
close all, clear all, clc;
figure ()
usamap('Arizona')
arizonahi = shaperead('usastatehi', 'UseGeoCoords', true,...
'Selector',{@(name) strcmpi(name,'Arizona'), 'Name'});
geoshow(arizonahi, 'FaceColor', [0.3 1.0, 0.675])
lat = [36];
lon = [-110];
% textm(arizonahi.LabelLat, arizonahi.LabelLon, arizonahi.Name,...
% 'HorizontalAlignment', 'center')
geoshow(lat,lon, 'DisplayType', 'point', 'MarkerEdgeColor', 'b', 'Linewidth', 2)
legend('geoshow')
0 Comments
Answers (1)
Payas Bahade
on 25 Nov 2019
Hi Nathan,
I have written a below mentioned code which addresses your adding marker and legend requirement:
close all; clear all; clc;
figure ()
usamap('Arizona')
arizonahi = shaperead('usastatehi', 'UseGeoCoords', true,...
'Selector',{@(name) strcmpi(name,'Arizona'), 'Name'});
h(1) = geoshow(arizonahi, 'FaceColor', [0.3 1.0, 0.675]);
lat = [36 34 32];% defining lattitude
lon = [-110 -112 -112];% defining longitude
h(2) = geoshow(lat(1),lon(1), 'DisplayType', 'point','Marker','o', 'MarkerEdgeColor', 'b', 'Linewidth', 2);% specifying sample marker 1
h(3) = geoshow(lat(2),lon(2), 'DisplayType', 'point','Marker','d', 'MarkerEdgeColor', 'r', 'Linewidth', 2);% specifying sample marker 2
h(4) = geoshow(lat(3),lon(3), 'DisplayType', 'point','Marker','s', 'MarkerEdgeColor', 'k', 'Linewidth', 2);% specifying sample marker 3
legend([h(2),h(3),h(4)],'Solar','Water','Wind');% plotting legend
Output:
For more details on marker specification, please refer this documentation link and and for legend refer this link.
Hope this helps!
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!