- Use the "findobj" function to find the legend(s) and the "delete" function to delete them: If you have multiple plots on the same figure (and thus multiple legends), the above will delete all of the legends for all of the plots. To only remove specific legends, you can delete the legend at a specific index:\n% Find and delete the legendlgd = findobj('type', 'legend')delete(lgd)delete(lgd(idx)) % where idx is the index of the legend(s) to delete
- If you do not want to delete the legend, you can turn off the legend's visibility:set(lgd(idx), 'visible', 'off')
How can I delete legends from a plot or subplot?
498 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Deniz Baturay
le 27 Mar 2016
Modifié(e) : MathWorks Support Team
le 3 Jan 2024
When I plot the model returned by the "fitlm" function, a legend is automatically added to the plot. I am creating multiple subplots, and would like to remove repetitive legends. How can I do this?
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 2 Jan 2024
Modifié(e) : MathWorks Support Team
le 3 Jan 2024
Below are two ways to remove a legend from a plot:
3 commentaires
RUBINEI DORNELES MACHADO
le 3 Mai 2020
Hi ... if you need delete specific legend in position x:
lgd.String(x)=[ ];
;)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!