MATLAB Answers

How do I make a figure legend multiple lines in MATLAB 7.11 (R2010b)?

900 views (last 30 days)
The string for my legend is too long to fit into one line. I would like to split it into multiple lines.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Jan 2011
To split legend to multiple lines, use ASCII character 10 for new line, for example:
plot(sin(1:10),'b')
hold on
plot(cos(1:10),'r')
legend({['blue' char(10) 'line'],'red line'})

  0 Comments

Sign in to comment.

More Answers (1)

Christoforos Kanavakis
Christoforos Kanavakis on 23 Mar 2018
In newer versions, Matlab recommends using 'newline'.
So,
legend({['blue' newline 'line'],'red line'})

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

No tags entered yet.

Products


Release

R2010b