Effacer les filtres
Effacer les filtres

How to add a line break in categorical array?

15 vues (au cours des 30 derniers jours)
Vidura Vishvanath
Vidura Vishvanath le 14 Juil 2022
I want to add a line break between the season and months in the following bar chart. For example,
First Inter-monsoon
(March - April)
Any help is appreciated.
X = categorical({'First Inter-monsoon (March - April)','Southwest-monsoon (May - September)','Second Inter-monsoon (October-November)','Northeast-monsoon (December - February)'});
Y = [89 165 128 78; 41 106 54 38; NaN NaN 2.1 1.4];
b=bar(X,Y,'LineWidth',1)
b =
1×3 Bar array: Bar Bar Bar
colororder('default')

Réponse acceptée

the cyclist
the cyclist le 14 Juil 2022
Here is one way:
X = categorical({sprintf('First Inter-monsoon\\newline (March - April)'), ...
sprintf('Southwest-monsoon\\newline (May - September)'), ...
sprintf('Second Inter-monsoon\\newline (October-November)'), ...
sprintf('Northeast-monsoon\\newline (December - February)')});
Y = [89 165 128 78; 41 106 54 38; NaN NaN 2.1 1.4];
figure
b=bar(X,Y,'LineWidth',1);
colororder('default')

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by