Xticklabel to split into two lines

228 vues (au cours des 30 derniers jours)
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco le 10 Déc 2021
Commenté : Star Strider le 13 Déc 2021
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

Réponse acceptée

Star Strider
Star Strider le 10 Déc 2021
This has been updated to work in more recent releases.
.
  2 commentaires
Giuseppe Degan Di Dieco
Giuseppe Degan Di Dieco le 13 Déc 2021
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 le 13 Déc 2021
As always, my pleasure!
I attempted to do something similar myself, then found this link and MathWorks’ solution, and just went with it.
.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Connectez-vous pour commenter.

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by