Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Boxplot with multiline x axis labels

755 views
Skip to first unread message

Mark

unread,
Oct 3, 2011, 3:35:24 PM10/3/11
to
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');

Mark

unread,
Oct 4, 2011, 11:38:10 AM10/4/11
to
Can't anyone help on this? Maybe Mathworks employees?



"Mark" wrote in message <j6d2ps$bnh$1...@newscl01ah.mathworks.com>...

Tom Lane

unread,
Oct 6, 2011, 1:33:58 PM10/6/11
to
> 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


Mark

unread,
Oct 6, 2011, 2:26:29 PM10/6/11
to
Tom: thanks a lot, your code works very well. It achieves what I was looking for.



"Tom Lane" <tl...@mathworks.com> wrote in message <j6koqf$9ho$1...@newscl01ah.mathworks.com>...
0 new messages