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.
Comments
Post a Comment