Thread Subject: boxplot

Subject: boxplot

From: Thamar van Esch

Date: 14 Nov, 2008 14:50:03

Message: 1 of 8

Is there a way to control the y-axis features in boxplot? I would like to change the label ('Values' is default) and set the scale manually, but the regular 'set(gca,...)' does not work for boxplot.

Thanks

Subject: boxplot

From: Michael

Date: 14 Nov, 2008 17:54:47

Message: 2 of 8

On Nov 14, 6:50=A0am, "Thamar van Esch" <thamarvane...@gmail.com> wrote:
> Is there a way to control the y-axis features in boxplot? I would like to=
 change the label ('Values' is default) and set the scale manually, but the=
 regular 'set(gca,...)' does not work for boxplot.
>
> Thanks

a=3D[1;2;3]
ah=3Daxes
boxplot(a)
ylabel(ah,'These are my values')

Subject: boxplot

From: Pekka Kumpulainen

Date: 17 Nov, 2008 08:28:02

Message: 3 of 8

"Thamar van Esch" <thamarvanesch@gmail.com> wrote in message <gfk36r$bca$1@fred.mathworks.com>...
> Is there a way to control the y-axis features in boxplot? I would like to change the label ('Values' is default) and set the scale manually, but the regular 'set(gca,...)' does not work for boxplot.
>
> Thanks

What is it exactly that doesn't work?
At least these do work:
boxplot(randn(100,3))
set(gca,'YLim',[-5 5], ...)
'YTick',[-2 0 2], ...
'YTickLabel',{'L-2' 'L0' 'L2'});

Subject: boxplot

From: Lars Barring

Date: 17 Nov, 2008 17:40:17

Message: 4 of 8

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote i
> "Thamar van Esch" <thamarvanesch@gmail.com> wrote
> > Is there a way to control the y-axis features in boxplot? I would like to change the
> > label ('Values' is default) and set the scale manually, but the regular 'set(gca,...)'
> > does not work for boxplot.
>
> What is it exactly that doesn't work?
> At least these do work:
> boxplot(randn(100,3))
> set(gca,'YLim',[-5 5], ...)
> 'YTick',[-2 0 2], ...
> 'YTickLabel',{'L-2' 'L0' 'L2'});

Well, I do not know specifically about the y axis labels but I had the same
experience with x axis labels. Maybe you were trying to have horizontal boxes?

Whichever, this is my experience:
After considerable investigations it turned out that the x axis labels in my plot were
not actually x axis labels (in the ordinary sense), but rather text object that are
children to the "boxplot" hggroup (the normal x axis labels were just turned
off/empty). This is somehow controlled through a setappdata structure that I did not
really bother to analyse in detail. Then there were listeners that sort of prevented
me from adding normal x axis labels but instead directed some (but not all) of the
adjustments that I was trying to do to these text object.

To cut a long and boring story short, I spent something like six hours (!!) of
concentrated work on creating a something like a publication quality boxplot
because of the most unintuitive construction of the boxplot object.

And, to try to draw some general conclusion out of this experience, this is not the
first time that I find Matlab plot objects difficult because of more or less hidden
'functionality' (bug or feature??). Another example is the colorbar issue where
attempts to make it nice and always well placed and scaled directly interfere with
the possibility to tailor the layout to specific need.


Lars

Subject: boxplot

From: Pekka Kumpulainen

Date: 18 Nov, 2008 10:33:01

Message: 5 of 8

"Lars Barring" <lars.barring@myworkplace.se> wrote in message <gfsaa1$g5q$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote i
> > "Thamar van Esch" <thamarvanesch@gmail.com> wrote
> > > Is there a way to control the y-axis features in boxplot? I would like to change the
> > > label ('Values' is default) and set the scale manually, but the regular 'set(gca,...)'
> > > does not work for boxplot.
> >
> > What is it exactly that doesn't work?
> > At least these do work:
> > boxplot(randn(100,3))
> > set(gca,'YLim',[-5 5], ...)
> > 'YTick',[-2 0 2], ...
> > 'YTickLabel',{'L-2' 'L0' 'L2'});
>
> Well, I do not know specifically about the y axis labels but I had the same
> experience with x axis labels. Maybe you were trying to have horizontal boxes?
>
> Whichever, this is my experience:
> After considerable investigations it turned out that the x axis labels in my plot were
> not actually x axis labels (in the ordinary sense), but rather text object that are
> children to the "boxplot" hggroup (the normal x axis labels were just turned
> off/empty). This is somehow controlled through a setappdata structure that I did not
> really bother to analyse in detail. Then there were listeners that sort of prevented
> me from adding normal x axis labels but instead directed some (but not all) of the
> adjustments that I was trying to do to these text object.
>
> To cut a long and boring story short, I spent something like six hours (!!) of
> concentrated work on creating a something like a publication quality boxplot
> because of the most unintuitive construction of the boxplot object.
>
> And, to try to draw some general conclusion out of this experience, this is not the
> first time that I find Matlab plot objects difficult because of more or less hidden
> 'functionality' (bug or feature??). Another example is the colorbar issue where
> attempts to make it nice and always well placed and scaled directly interfere with
> the possibility to tailor the layout to specific need.
>
>
> Lars

OK, this clears the situation.
Yes, boxplot is one of those "nice" creatures who do a lot of things inside.
Legend is another one, I really burned my sleeves with it some time ago. Extremely slow, usually in wrong place, unnecessary line and text objects created inside. I wrote my own for that purpose (several releases ago).

You can give the labels in call
h=boxplot(...'Labels',...)
h will be a matrix of handles to the line objects (not mentioned in documentation)
The line objects also have tags that can be used to find their handles.
But the Labels have no tag. You can find their handles among the children of the hggroup object, which is the only child of the axis:
 hcc = get(get(gca,'Children'),'Children');
Usually the lables are the first ones (in reverse order from right to left). The only ones of type text anyway: hl = findobj(hcc,'type','text')
Now you can set their properties.

One reason why they use separate text objects instead of XTickLabels (or Y..) might be that tixklabels dont support tex or rotating, which is an option in boxplot.
But yes, could be more clear. However most things can be specified in the input arguments of boxplot.

Subject: boxplot

From: Lars Barring

Date: 18 Nov, 2008 17:22:02

Message: 6 of 8

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote ...
> "Lars Barring" <lars.barring@myworkplace.se> wrote ...
...
> One reason why they use separate text objects instead of XTickLabels (or Y..)
> might be that tixklabels dont support tex or rotating, which is an option in boxplot.
> But yes, could be more clear. However most things can be specified in the input
> arguments of boxplot.

I wanted to have the x ticks not rotated 90 degrees but slanting at 40-60
degrees. Which I normally achieve with the excellent FEX routine ROTATETICKLABEL.
And I wanted my labels to include TeX formatting (Greek letters as subscripts).
Both to which the BOXPLOT "x-labels" were completely indifferent. Well, I
digged deep enough to come up with this solution

hA=subplot(2,2,1);
boxplot(c(L,1:n1))
set(hA,'FontSize',11,'YLim',[ymin 1],'Position',[0.08 0.62 0.39 0.32]);
hB=findobj(hA,'Type','hggroup');
hL=findobj(hB,'Type','text');
delete(hL)
set(gca,'XTick',[1:n1]);
set(gca,'XTickLabel',IXName');
hT=rotateticklabel(gca,-30);
for k=1:n1,
  set(hT(k),'FontSize',11,'Position',[k ymin*dd 0]);
end

The rather "interesting" but counterintuitive result of this tweak is
that I get a plot that looks as I want, *but* the x-tick labels (i.e the
hT text objects) are still children under the BOXPLOT hggroup.
Bug or feature????

I am sure that there is a perfectly valid explanation to this behaviour
(along the lines you mention; rotation etc). But what really beats me is
why this is implemented in this rather unintuitive, inconsistent with other
plot functions, and totally undocumented and difficult to find way [sorry about
all these un- and in- words but I spent some 6 hours on this, including finding
a useful dd vertical displacement of the text].

TMW: why not just do the right thing and make the axis labels available as
children to the axes object with some nice and useful defaults ??


Lars

Subject: boxplot

From: Pekka Kumpulainen

Date: 18 Nov, 2008 18:34:02

Message: 7 of 8

"Lars Barring" <lars.barring@myworkplace.se> wrote in message <gfutjq$6q7$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote ...
> > "Lars Barring" <lars.barring@myworkplace.se> wrote ...
> ...
> > One reason why they use separate text objects instead of XTickLabels (or Y..)
> > might be that tixklabels dont support tex or rotating, which is an option in boxplot.
> > But yes, could be more clear. However most things can be specified in the input
> > arguments of boxplot.
>
> I wanted to have the x ticks not rotated 90 degrees but slanting at 40-60
> degrees. Which I normally achieve with the excellent FEX routine ROTATETICKLABEL.
> And I wanted my labels to include TeX formatting (Greek letters as subscripts).
> Both to which the BOXPLOT "x-labels" were completely indifferent. Well, I
> digged deep enough to come up with this solution
>
> hA=subplot(2,2,1);
> boxplot(c(L,1:n1))
> set(hA,'FontSize',11,'YLim',[ymin 1],'Position',[0.08 0.62 0.39 0.32]);
> hB=findobj(hA,'Type','hggroup');
> hL=findobj(hB,'Type','text');
> delete(hL)
> set(gca,'XTick',[1:n1]);
> set(gca,'XTickLabel',IXName');
> hT=rotateticklabel(gca,-30);
> for k=1:n1,
> set(hT(k),'FontSize',11,'Position',[k ymin*dd 0]);
> end
>
> The rather "interesting" but counterintuitive result of this tweak is
> that I get a plot that looks as I want, *but* the x-tick labels (i.e the
> hT text objects) are still children under the BOXPLOT hggroup.
> Bug or feature????
>
> I am sure that there is a perfectly valid explanation to this behaviour
> (along the lines you mention; rotation etc). But what really beats me is
> why this is implemented in this rather unintuitive, inconsistent with other
> plot functions, and totally undocumented and difficult to find way [sorry about
> all these un- and in- words but I spent some 6 hours on this, including finding
> a useful dd vertical displacement of the text].
>
> TMW: why not just do the right thing and make the axis labels available as
> children to the axes object with some nice and useful defaults ??
>
>
> Lars

Why not simply modify the existing text objects? You have the handles in hL,
set(hL,'Rotation',30,'Interpreter','latex')

Ticklabels are special creatures and you are definitely not the only one wishing they would some day support the full set of text object properties, or even close...

Subject: boxplot

From: Lars Barring

Date: 18 Nov, 2008 20:09:02

Message: 8 of 8

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message

>>>> SNIP

> > And I wanted my labels to include TeX formatting (Greek letters as subscripts).
> > Both to which the BOXPLOT "x-labels" were completely indifferent. Well, I
> > digged deep enough to come up with this solution
> >
> > hA=subplot(2,2,1);
> > boxplot(c(L,1:n1))
> > set(hA,'FontSize',11,'YLim',[ymin 1],'Position',[0.08 0.62 0.39 0.32]);
> > hB=findobj(hA,'Type','hggroup');
> > hL=findobj(hB,'Type','text');
> > delete(hL)
> > set(gca,'XTick',[1:n1]);
> > set(gca,'XTickLabel',IXName');
> > hT=rotateticklabel(gca,-30);
> > for k=1:n1,
> > set(hT(k),'FontSize',11,'Position',[k ymin*dd 0]);
> > end
> >
> > The rather "interesting" but counterintuitive result of this tweak is
> > that I get a plot that looks as I want, *but* the x-tick labels (i.e the
> > hT text objects) are still children under the BOXPLOT hggroup.
> > Bug or feature????
>>>>>>> SNIP
 
> Why not simply modify the existing text objects? You have the handles in hL,
> set(hL,'Rotation',30,'Interpreter','latex')
>
> Ticklabels are special creatures and you are definitely not the only one wishing
> they would some day support the full set of text object properties, or even
> close...

Well, maybe I did something wrong in all the test and trials I had to experiment
with. But when I tried that, the text object did not react. They just stayed either
horizontal or vertical, and LaTeX was not accepted .... What I believe my code did was to create the text objects (with the right interpreter turned on and rotated
to my taste) and as such they were then hooked up as label children to the
BOXPLOT hggroup.

Lars

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
ylabel scale Thamar van Esch 14 Nov, 2008 09:50:19
rssFeed for this Thread

Contact us at files@mathworks.com