Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Boxplot with multiline x axis labels

Subject: Boxplot with multiline x axis labels

From: Mark

Date: 3 Oct, 2011 19:35:24

Message: 1 of 4

Hello,

I'm trying to create a boxplot for two groups. Each group's label is multi line. I have tried the approach below, but the first line of each label is drawn on top of the x axis, while the second is drawn below the x axis (please try the code below)

Does anyone know how to make the two lines be drawn below the x axis in a boxplot?

Thanks

%%%%%%%%%%%
Dist1 = rand(10, 1);
Dist2 = rand(10, 1);

group = [repmat(cellstr(sprintf('First Line G1\nSecond Line G1')), length(Dist1), 1); ...
         repmat(cellstr(sprintf('First Line G2\nSecond Line G2')), length(Dist2), 1)];

figurePlot = figure('visible', 'on');
boxplot([Dist1;Dist2], group)
ylabel('Y Label');

Subject: Boxplot with multiline x axis labels

From: Mark

Date: 4 Oct, 2011 15:38:10

Message: 2 of 4

Can't anyone help on this? Maybe Mathworks employees?



"Mark" wrote in message <j6d2ps$bnh$1@newscl01ah.mathworks.com>...
> Hello,
>
> I'm trying to create a boxplot for two groups. Each group's label is multi line. I have tried the approach below, but the first line of each label is drawn on top of the x axis, while the second is drawn below the x axis (please try the code below)
>
> Does anyone know how to make the two lines be drawn below the x axis in a boxplot?
>
> Thanks
>
> %%%%%%%%%%%
> Dist1 = rand(10, 1);
> Dist2 = rand(10, 1);
>
> group = [repmat(cellstr(sprintf('First Line G1\nSecond Line G1')), length(Dist1), 1); ...
> repmat(cellstr(sprintf('First Line G2\nSecond Line G2')), length(Dist2), 1)];
>
> figurePlot = figure('visible', 'on');
> boxplot([Dist1;Dist2], group)
> ylabel('Y Label');

Subject: Boxplot with multiline x axis labels

From: Tom Lane

Date: 6 Oct, 2011 17:33:58

Message: 3 of 4

> Can't anyone help on this? Maybe Mathworks employees?

Mark, in general I don't know of a way to have multi-line axis tick labels.
The boxplot function goes to great lengths to draw text under the axis
locations in order to deal with this. While this might be too much of a hack
for your taste, here's a way to tap into that boxplot behavior:

Dist1 = rand(10, 1);
Dist2 = rand(10, 1);

group1 = [repmat(cellstr('First Line G1'), length(Dist1), 1); ...
          repmat(cellstr('First Line G2'), length(Dist2), 1)];
group2 = [repmat(cellstr('Second Line G1'), length(Dist1), 1); ...
          repmat(cellstr('Second Line G2'), length(Dist2), 1)];

figurePlot = figure('visible', 'on');
boxplot([Dist1;Dist2], {group1 group2})
ylabel('Y Label');

-- Tom
 

Subject: Boxplot with multiline x axis labels

From: Mark

Date: 6 Oct, 2011 18:26:29

Message: 4 of 4

Tom: thanks a lot, your code works very well. It achieves what I was looking for.



"Tom Lane" <tlane@mathworks.com> wrote in message <j6koqf$9ho$1@newscl01ah.mathworks.com>...
> > Can't anyone help on this? Maybe Mathworks employees?
>
> Mark, in general I don't know of a way to have multi-line axis tick labels.
> The boxplot function goes to great lengths to draw text under the axis
> locations in order to deal with this. While this might be too much of a hack
> for your taste, here's a way to tap into that boxplot behavior:
>
> Dist1 = rand(10, 1);
> Dist2 = rand(10, 1);
>
> group1 = [repmat(cellstr('First Line G1'), length(Dist1), 1); ...
> repmat(cellstr('First Line G2'), length(Dist2), 1)];
> group2 = [repmat(cellstr('Second Line G1'), length(Dist1), 1); ...
> repmat(cellstr('Second Line G2'), length(Dist2), 1)];
>
> figurePlot = figure('visible', 'on');
> boxplot([Dist1;Dist2], {group1 group2})
> ylabel('Y Label');
>
> -- Tom
>

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us