Why we can't directly delete Legend entries?

33 vues (au cours des 30 derniers jours)
maro
maro le 12 Mai 2013
Hi,
As in question Why we can't directly delete Legend entries from Matlab figure?

Réponses (3)

Mike D.
Mike D. le 15 Oct 2018
What if you didn't want to delete the curves/lines from the plot, but only wanted certain things deleted from the legend?
  7 commentaires
Mike D.
Mike D. le 16 Oct 2018
Modifié(e) : Walter Roberson le 16 Oct 2018
I'm not seeing doMarkDirty do anything, but the following works for removing curves from legend of a mapping toolbox figure:
Select curve on the mapping figure, and type this:
h = gco;
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
legend off
legend
Andrea Mariscotti
Andrea Mariscotti le 28 Jan 2024
@Mike D. Thank you! I was touching up an old plot for a paper: it works!

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 12 Mai 2013
Modifié(e) : Image Analyst le 12 Mai 2013
I don't know. You have to do it indirectly, such as by reissuing the legend command with fewer entries, or by calling findobj(), finding the entry you wish to delete, and then calling delete(itemHandle). Calling legend() again is not too bad - you already have the strings, so it's not too much trouble just to leave one off - that's about the same work to do than if you did something like (unsupported) legend('Remove', stringToRemove);

Jacob Moreland
Jacob Moreland le 1 Mar 2018
This is an old question, but this works in MATLAB 2015a, delete the lines you want to remove from the legend, delete the legend, and then ctrl-z to bring the legend back, and the legend should come back with only the legend entries removed.
  1 commentaire
Walter Roberson
Walter Roberson le 1 Mar 2018
With recent versions of MATLAB, delete the lines you want to remove from the legend, and then command
legend show
to have it update the legend.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by