Xticklabel to split into two lines

조회 수: 270 (최근 30일)
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021년 12월 10일
댓글: Star Strider 2021년 12월 13일
Dear All,
hope you are doing well.
I'd very grateful if you cold help me in understanding how to split a label for a bar xtick into two lines.
As you can see from the attached plot, it happens that the string 'Steel/concrete composite' is too long, and I'd would have something like 'Steel/concrete' in the upper line, and 'composite' below, that is
Steel/concrete
composite
Thanks for your time and help in advance, and best!
---
Giuseppe

채택된 답변

Star Strider
Star Strider 2021년 12월 10일
This has been updated to work in more recent releases.
.
  댓글 수: 2
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021년 12월 13일
Thanks Star Strider for the tip.
At the provided link there's a comprehensive guide for multi-line axis ticks.
Best.
Star Strider
Star Strider 2021년 12월 13일
As always, my pleasure!
I attempted to do something similar myself, then found this link and MathWorks’ solution, and just went with it.
.

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

추가 답변 (1개)

Voss
Voss 2021년 12월 10일
Maybe this will work:
set(gca(),'XTickLabel',{'Concrete' 'Masonry' 'Steel' sprintf('Steel/concrete\\newlinecomposite')});
  댓글 수: 1
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco 2021년 12월 13일
Thank you Benjamin.
Your solution is very straightforward and easy to code.
Thanks for your consideration.
Best.

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

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by