Multi-line legend strings

조회 수: 132 (최근 30일)
Matt Raum
Matt Raum 2018년 4월 10일
답변: Daniel Svedbrand 2019년 2월 13일
I recently upgraded from R2011b to R2017a. In R2011b I was able to create legend entries with multiple lines e.g.:
figure;
plot(1,1,'o');
legend(sprintf('hello\nworld'));
In 2017a this no longer seems to be possible. The text displayed in the legend is the literal string "hello\nworld" and I get the following warning:
Warning: Error updating Legend.
Character vector must have valid interpreter syntax:
hello\nworld
Furthermore, the legend text overruns the bounding box that is drawn for the legend. In both R2011b and R2017a, the 'interpreter' property for the legend object defaults to 'tex'. I've tried using both 'none' and 'latex' as the R2017a interpreter but still get the same results.
Is there a way to have a multi-line legend string in R2017a?
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2018년 4월 10일
The legend displays correctly in R2017a in Windows 10.

댓글을 달려면 로그인하십시오.

답변 (2개)

Daniel Svedbrand
Daniel Svedbrand 2019년 2월 13일
use \newline instead of \n and skip "sprintf"
legend('hello\newlineworld');

the cyclist
the cyclist 2018년 4월 11일
Maybe you have a different interpreter?
If you do
figure;
plot(1,1,'o');
hL = legend(sprintf('hello\nworld'));
What do you get from
hL.Interpreter
? Mine is 'tex'

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by