Add Legend Automatically Based on Tag Property Value

Add legend to axes based on values from plot handles Tag property

Vous suivez désormais cette soumission

Instead of adding a legend manually and making sure the colors are consistent, use the 'Tag' property for each plot to separate them. Then use the function add_legend to add a legend. The function groups all plots based on their Tag property, and give each group a separate color. It uses the Tag property values as labels in the legend.
I have included the function varycolor by Daniel Helmick:

https://www.mathworks.com/matlabcentral/fileexchange/21050-varycolor

Citation pour cette source

Hannes Mogensen (2026). Add Legend Automatically Based on Tag Property Value (https://fr.mathworks.com/matlabcentral/fileexchange/58456-add-legend-automatically-based-on-tag-property-value), MATLAB Central File Exchange. Extrait(e) le .

Remerciements

Inspiré par : varycolor

Informations générales

Compatibilité avec les versions de MATLAB

  • Compatible avec toutes les versions

Plateformes compatibles

  • Windows
  • macOS
  • Linux
Version Publié le Notes de version Action
1.0.0.0

Added credit to Daniel Helmick

Updated description