Search code examples
matlabmatlab-figure

Rotate multi line xlabels for boxplot in matlab


I want to make a boxplot with rotated xlabels. For a simple case this works:

SCAgroups = [1, 1, 2];
SCAgroups2 = {'a', 'b', 'a'};
fH = figure();
aH = axes(fH);
boxplot(aH, CVval, SCAgroups);
xtickangle(aH, 90);

Rotated Xlabels

Now I have 2 labels to group the data:

SCAgroups = [1, 1, 2];
SCAgroups2 = {'a', 'b', 'a'};
fH = figure();
aH = axes(fH);
boxplot(aH, CVval, {SCAgroups, SCAgroups2});
xtickangle(aH, 90);

Rotation does not work

How to get rotated Xlabels when the labels are multi-line?


Solution

  • There is a boxplot parameter 'LabelOrientation' for this:

    SCAgroups = [1, 1, 2];
    SCAgroups2 = {'a', 'b', 'a'};
    fH = figure();
    aH = axes(fH);
    boxplot(aH, rand(2,3), {SCAgroups, SCAgroups2},'LabelOrientation','inline');
    

    enter image description here