How to add a line break in categorical array?

19 visualizaciones (últimos 30 días)
Vidura Vishvanath
Vidura Vishvanath el 14 de Jul. de 2022
Respondida: the cyclist el 14 de Jul. de 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')

Respuesta aceptada

the cyclist
the cyclist el 14 de Jul. de 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')

Más respuestas (0)

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by