Info

This question is closed. Reopen it to edit or answer.

Skipping items in a Legend (R2014a)

1 view (last 30 days)
Kevin McAughey
Kevin McAughey on 18 Aug 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
I am trying to avoid showing an object in the legend for a figure, and in past releases this was possible in a number of ways, as described in the answers to this question.
However, in R2014a this behaviour appears to have changed, with the suppressed handle object continuing to appear in the legend. I was wondering if anyone has experienced this, and has a workaround?

Answers (1)

Star Strider
Star Strider on 18 Aug 2015
The corresponding page for R2014a is Controlling Legend Content.
  2 Comments
Kevin McAughey
Kevin McAughey on 19 Aug 2015
The behaviour described in the documentation does not seem to match the behaviour that I'm observing.
When I have my already existing figure I run the following code:
hold on
h6 = plot(xx,yy,'r'); % Add data to be excluded from legend
set(get(get(h6,''Annotation'),'LegendInformation'),'IconDisplayStyle',...
'off'); % Hide object described by handle h6 from legend
legend('Test 1','Test 2') % Show legend
As I understand it this code should display a legend with the previous two data sets that were present on the figure, with names Test 1 and Test 2, while hiding the line described by h6. This is not the case, as all three data sets are shown in the legend.
Star Strider
Star Strider on 19 Aug 2015
It seems your code has a context you didn’t provide. It would help if you included it.

Community Treasure Hunt

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

Start Hunting!