フィルターのクリア

Adding a Legend to Scatter Shapes on a Map

16 ビュー (過去 30 日間)
Claire Hollow
Claire Hollow 2020 年 7 月 8 日
コメント済み: Claire Hollow 2020 年 7 月 8 日
Hello! I have a map of Nebraska I got by doing this
figure(1)
usamap('Nebraska')
nebraskahi = shaperead('usastatehi', 'UseGeoCoords', true,...
'Selector',{@(name) strcmpi(name,'Nebraska'), 'Name'});
geoshow(nebraskahi, 'FaceColor', [0.3 1.0, 0.675])
hold on
and then I use scatterm to plot different points on the map by longitude and latitude.
I have been using different shapes (circles, squares and diamonds) in scatterm for different kinds of points. I am trying to make a legend only to lable what the circles, squares and diamonds mean. Whenever I try to just do legend('Circle Meaning','Square Meaning','Diamond Meaning') it doesn't give me the scatter shapes and instead gives me lines (I'm assuming from the map). Please let me know how to do this, thank you advance for the help!

採用された回答

Adam Danz
Adam Danz 2020 年 7 月 8 日
Step 1: Define the legend strings using DisplayName
Example
h1 = scatter(___, 'd', 'DisplayName', 'Diamond meaning');
h2 = scatter(___, 'o', 'DisplayName', 'Circle meaning');
h3 = scatter(___, 's', 'DisplayName', 'Square meaning');
Step 2: Provide the scatter object handles as inputs to legend()
Example
legend([h1(1), h2(1), h3(1)])
  • No need to specify the legend string becaues it's already done in step 1.
  • The "(1)" indexing is just in case your handles are larger than 1x1.
  1 件のコメント
Claire Hollow
Claire Hollow 2020 年 7 月 8 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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