Why does the LEGEND function only display 20 strings in MATLAB 7.4 (R2007a)?

If I execute the following commands:
plot(rand(25))
legend('show')
only the 20 first text strings are displayed in the legend.

 Réponse acceptée

This enhancement has been incorporated in Release 2008a (R2008a). Current versions of MATLAB now have a limit of 50 entries for legend. If you would like to add more entries than that, see the following MATLAB Answers post:
For previous product releases, read below for a possible workaround:
The maximum number of entries for a LEGEND is 20.
MATLAB is a viewable source language, meaning that you can access the source code and read and modify it. You can go into the code for LEGEND.M and change the number 20 on lines 628 and 630 to reflect whatever values you think are best.
if auto_children && length(ch) > 20,
% only automatically add first 20 to cut down on huge lists
ch = ch(1:20);
end
You change the MATLAB source code at your own risk and before editing the source code make a back-up of the file.

2 commentaires

Jan Kappen
Jan Kappen le 4 Mai 2018
Modifié(e) : Jan Kappen le 4 Mai 2018
Does not work in recent Matlab Versions (limit of 50). Please see https://de.mathworks.com/matlabcentral/answers/383371-how-to-make-all-the-legend-appear-in-a-plot. Any workaround?
nevermind, found it: https://de.mathworks.com/matlabcentral/answers/362378-why-does-my-legend-only-display-50-entries
Solution is to create multiple legends.
Hi Jan,
Thanks for bringing this up. We've updated the answer to point to that solution for newer versions.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2007a

Community Treasure Hunt

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

Start Hunting!

Translated by