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

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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 May 2018
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 Comments
Jan Kappen
Jan Kappen on 4 May 2018
Edited: Jan Kappen on 4 May 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.
Mary Abbott
Mary Abbott on 9 May 2018
Hi Jan,
Thanks for bringing this up. We've updated the answer to point to that solution for newer versions.

Sign in to comment.

More Answers (0)

Products


Release

R2007a

Community Treasure Hunt

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

Start Hunting!