matlab - Multiple Boxplot with various size of data set labeling -


i have read post most efficient way of drawing grouped boxplot matlab. code give oleg :

y     = rand(1000,1); x     = y-rand(1000,1); actid = randi(6,1000,1);  xylabel = repmat('xy',1000,1); boxplot([x; y], {repmat(actid,2,1), xylabel(:)} ,'factorgap',10) % retrieve handles text labels h = allchild(findall(gca,'type','hggroup'));  % delete x, y labels throw = findobj(h,'string','x','-or','string','y'); h     = setdiff(h,throw); delete(throw);  % center labels mylbl  = {'this','is','a','pain','in...','guess!'}; hlbl   = findall(h,'type','text'); pos    = cell2mat(get(hlbl,'pos'));  % new centered position first intra-group label newpos = num2cell([mean(reshape(pos(:,1),2,[]))' pos(1:2:end,2:end)],2); set(hlbl(1:2:end),{'pos'},newpos,{'string'},mylbl')  % delete second intra-group label delete(hlbl(2:2:end)) 

works pefectly fine. have question on 'handle' structure. in case have single data per number {1,2,3,4,5,6}, don't need xylabel , used boxplot([x; y], {repmat(actid,2,1) repmat('x',1000,1)} ,'factorgap',10) , works fine. why need use x labeling? if not use it, variable h has not 'data source' type , referenced 'line' type replacement of number strings not work anymore. know why?

thank help.

if i'm understanding correctly, you're asking how change xticklabel strings. if so, should trick:

y     = rand(1000,1); x     = y-rand(1000,1); actid = randi(6,1000,1);  boxplot([x; y],repmat(actid,2,1),'factorgap',10); mylbl  = {'this','is','a','pain','in...','guess!'}; set(gca,'xticklabel',mylbl) 

more details:

the second input boxplot function grouping variable(s). when 1 grouping variable used, boxplot changes xticklabel match grouping. can see entering get(gca,'xticklabel') right after boxplot command:

boxplot([x; y],repmat(actid,2,1),'factorgap',10) get(gca,'xticklabel') ans =      '1'     '2'     '3'     '4'     '5'     '6' 

if more 1 grouping variable used -- e.g. 2 -- boxplot has fancy in order label boxplots using both groupings (see picture below), so, sets xticklabel empty, inserts text objects instead. check out xticklabel after using 2 grouping variables:

boxplot([x; y], {repmat(actid,2,1), xylabel(:)} ,'factorgap',10) get(gca,'xticklabel') ans =      '' %// it's empty!!! 

which why do find text objects after using 2 grouping variables, not when use one.

using 2 grouping variables


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -