Subplots are not aligned when using boxplot. Why? Possible bug?

10 views (last 30 days)
Hi, I am doing a series of subplot and they are not vertical aligned. They are losing the alignment, Why? Please
see figure attached.
Thank you
  2 Comments
dpb
dpb on 16 Aug 2018
Would, at minimum, need to see code that generated and size/shape of data for each.
The ideal would be to attach a script including data that reproduces the problem; it could be just two series, no need for anything more than bare minimum to see the effect.
Rafael Freire
Rafael Freire on 16 Aug 2018
Hi, here is the code and the mat file to generate the plot
for i=1:51
subplot(7,8,i)
boxplot(area1all(:,i),c, 'symbol', 'k+')
set(gca, 'box','off','xtick',[],'ytick',[],'ztick',[],'xcolor',[1 1 1]);
end

Sign in to comment.

Answers (1)

dpb
dpb on 16 Aug 2018
Edited: dpb on 16 Aug 2018
I was able to understand part of it; some of it I still don't know the root cause...the attached is empirical and sets each subplot height to that of the first and the left position and width of each subplot in the leftmost column also to that in the first column.
One issue on the height is the magnitude of the values; if they're less than a threshold the default axes display will be with the common exponent; turning that off helps on the height but didn't seem to make it go away entirely, hence the fixup.
The left column start+width sum was the same for each one in the LH column but for some reason the start position was displaced to the right on some; I was not able to discern the root cause. Since the overall RH position was in the same place for all, setting them to the common start/width lines them up as well. This was necessary only for the first column with the specific data; whether it is data related or a remnant of so many plots on a given figure causing internal computational issues I can't tell.
Anyway, with the following script got the attached figure...you may still find other datasets "break" and will need more drastic heuristics -- one could wait until the whole thing is done then compute what the spacings need to be to evenly distribute the number and then reset them all from that computed array. That's doable but would take more time than I have at the moment to work out the algebra.
for i=1:51
hAx(i)= subplot(7,8,i);
boxplot(area1all(:,i),c, 'symbol', 'k+')
set(hAx(i), 'box','off','xtick',[],'ytick',[],'ztick',[], ...
'xcolor',[1 1 1]);
hAx(i).YAxis.Exponent=0; % the exponent takes space from data, turn off
if i==1 % save postion vector from first for reference
posn=hAx(i).Position; ht=posn(4); % first height
lft=posn(1); w=posn(3); % and left, width
else % all after first fixup height
posn=hAx(i).Position; % get the current position
posn(4)=ht; % set height to first in vector
if rem(i,8)==1 % if first column
posn(1)=lft; posn(3)=w; % set left,width
end
hAx(i).Position=posn; % and update the axes
end
end
  2 Comments
Rafael Freire
Rafael Freire on 18 Aug 2018
Edited: Rafael Freire on 18 Aug 2018
Thank you. This partially solved my problem, but....you can see that in row 4 column 1 the figure is partially missing and this error repeats through the whole figure for some cases (5,4) (3,5) etc... I think we found a bug ...
dpb
dpb on 18 Aug 2018
I don't get any numbers shown as does your original even w/o modifying the plot. Is the figure really from identically the pasted code?
I'm pretty sure the effect is from the magnitude of the data between the various cases compounded by smooshing the area into a small form factor such that the label heuristics probably break down.
As small as 3 rows seems to begin where slight discrepancies start to show up; if the data are variable; if one uses the same index for all, the place where discrepancies show up is at somewhat higher numbers of row,column for the subplot(). IOW, I think it's a combination of the data and what boxplot tries to output based on the magnitudes regarding axes values, etc., and the subplot computational area algorithm itself and interactions between -- the area for the axes is adjusted automagically by the size of the text labels and whether the exponent is/isn't shown, etc., etc., etc., ... there's a complex interaction there even for ordinary plot() and when add in the additional eomplexity of boxplot I guess I don't find it surprising.
Whether TMW would consider it a bug I don't know; you can complain via the formal support link and see what response you get.

Sign in to comment.

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!