Graph Legend not picking up third plot marker

4 visualizaciones (últimos 30 días)
Chloe Whitton
Chloe Whitton el 8 de Abr. de 2021
Respondida: Adam Danz el 8 de Abr. de 2021
I've created a graph and tired to add in a legend to describe what each plot is however, MATLAB doesn't seem to be picking up the symbol for 'Toe off', it should be the red square. Does anyone know how to fix this issue? I've attached a screenshot of the code and the graph produced.
Thanks

Respuestas (2)

Star Strider
Star Strider el 8 de Abr. de 2021
It is likely not possible to determine what the problem is without the actual data and relevant code.
In their absence, try this:
figure
hp{1} = plot(time, ankle_V);
hold on
hp{2} = plot(time(ankle_HS_V), zeros(size(ankle_HS_V)), 'g*');
hp{3} = plot(time(ankle_TO_V), zeros(size(ankle_TO_V)), 'rs');
hold off
legend([hp{:}],'Ankle Velocity', 'Heel Strike', 'Toe Off')
See if that does what you want.

Adam Danz
Adam Danz el 8 de Abr. de 2021
There are multiple objects with the green asterisk and they are higher up in the uistack than the red squares. Since you're providing only 3 legend strings, the legend is choosing the first 3 items in the uistack which, apparently, are the blue line and the first two green astersks.
Instead use the DisplayName property to assign legend strings and then specify which object handles should appear in the legend
Follow this example.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by