Xticklabel to split into two lines

270 次查看(过去 30 天)
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
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
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