How to add a legend in the Mapping Toolbox?

13 visualizaciones (últimos 30 días)
Kamila Turczewski
Kamila Turczewski el 19 de Ag. de 2019
Comentada: Adam Danz el 21 de Ag. de 2019
I'm trying to add a legend for serveral values that I plotted on a map using scatterm().
I simply want to add a legend and I'm having a hard time finding it in the Mapping Toolbox and online in MatLab answers. I want the blue, red, and grey values to be legend('P-Value < 5%', ' 5% < P-Value < 15%' , 'P-Value > 15%') correspondingly. Normal legend() doesn't work.
Here is the code:
latlim = [25 50]; lonlim = [-125 -67];
axe = usamap(latlim, lonlim);
set(axe, 'Visible', 'off');
sheds = shaperead('usastatehi','UseGeoCoords', true, 'BoundingBox', [lonlim', latlim']);
geoshow(axe, sheds, 'FaceColor', [1 1 1])
scatterm(latb, longb, 12, blueVal, 'filled', 'blue')
hold on
scatterm(latr, longr, 12, redVal, 'filled', 'red')
scatterm(latg, longg, 12, [0.7 0.7 0.7])
  1 comentario
Adam Danz
Adam Danz el 21 de Ag. de 2019
" Normal legend() doesn't work. "
If you have any trouble implementing the answer (that uses a normal legend), please let us know what the prblems are.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 19 de Ag. de 2019
Editada: Adam Danz el 20 de Ag. de 2019
Use the DisplayName property (you can change the labels from my example)
Use the output handles produced in scatterm()
Provide those handles to legend().
h(1) = scatterm(latb, longb, 12, blueVal, 'filled', 'blue','DisplayName', 'p < 5%');
hold on
h(2) = scatterm(latr, longr, 12, redVal, 'filled', 'red','DisplayName', '5% < p < 15%');
h(3) = scatterm(latg, longg, 12, [0.7 0.7 0.7], 'DisplayName', 'p > 15%');
legend(h)
190820 093531-Figure 1.jpg

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by