Graph Legend not picking up third plot marker

8 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by