Graph Legend not picking up third plot marker

조회 수: 7 (최근 30일)
Chloe Whitton
Chloe Whitton 2021년 4월 8일
답변: Adam Danz 2021년 4월 8일
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

답변 (2개)

Star Strider
Star Strider 2021년 4월 8일
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 2021년 4월 8일
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.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by