xlabel in box plot

Hello all, I need help concerning the xlabel in my box plot. I am using this (part of) code:
boxplot(AB, 'Labels',{'1','2','3','4','5','6','7','8','9','10','11','12'})
xlabel('X Y Z')
So, if possible, I need X under 1 2 3 4, Y under 5 6 7 8 and Z under 9 10 11 12 with X, Y and Z entered. Could anyone please help me with this subject?
Greetings, Paulo Sousa

回答(1 个)

dpb
dpb 2015-7-12
Like
text([2.5:4:12].',-0.1*ones(3,1),['X';'Y';'Z'],'horizontal','center')
maybe?

4 个评论

No!
I have:
boxplot(AB, 'Labels',{'1','2','3','4','5','6','7','8','9','10','11','12'})
text(2.25,-0.4,'A')
text(6.25,-0.4,'B')
text(10.15,-0.4,'C')
And I need: an horizontal line or a curly bracket below 1 2 3 4 and X below the horizontal line (or the curly bracket). Is this possible?
Did you try it!!!???
I don't know what your AB is so no idea on what the y-scale is so for testing I just used
AB=rand(12);
before the boxplot call as you wrote it. That meant the ylim range on the y-axis was 0-1 which is why the text y-position of -0.1 worked well here. Obviously, move that based on your y-axis scale; apparently -0.4 worked; it's also possible to make those positions absolute instead of scaled to the axes or to compute a location based on the scale factor to make them invariant to data if you're doing this more than once. If you do desire that someone really try to duplicate your plot, attach the data as a .mat file so can actually create the same plot as you have.
I don't follow the 'A','B','C' above when you then say you want 'X' so not at all clear what you actually want the end result to be. If you're trying to show groupings, I'd probably change the labels to be
boxplot(AB, 'Labels',{'{1','2','3','4}','{5','6','7','8}','{9','10','11','12}'})
to put the curlies around the labels to indicate the groups there essentially automagically. The x- position as [2.5:4:12] combined with 'horizontal','center' serves to ensure the text written is centered at the location on the x axis that is precisely on the midpoint; you don't need to try to "fudge" on the position to make the characters appear where you want based on font and fontsize, etc., etc., etc., ...; just use the alignment property to center whatever is written at the correct position.
If you want to draw a line as well, then line will let you do that as well or you could alternatively to individual text/line pieces use one of the arrows available with the annotation object. See
doc annotation % for details
can you make the text lable in italic?
Look at the properties of the object -- 'FontStyle'

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

评论:

dpb
2020-4-30

Community Treasure Hunt

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

Start Hunting!

Translated by