How to add a line break in categorical array?

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

采纳的回答

the cyclist
the cyclist 2022-7-14
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')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by