4

I am creating a GUI in MATLAB using GUIDE. I have several axes, and in one of them I want to draw a boxplot. My problem is that after drawing the boxplot, the size of the axes changes, and it overlaps with some of my other figures.

To replicate this problem, create a .fig file using GUIDE containing two axes: axes1 and axes2, as shown in the figure: Example of .fig with two axes.

Then, in the OpeningFcn, add the following lines:

Z = normrnd(1,3,[100,1]);
plot(handles.axes1, Z);
boxplot(handles.axes2,Z)

Then lauch the GUI. I see the following:

GUI when launching the program

As you can see, the two axes overlap. I've tried changing the properties of the box plot, but with no luck.

I use MATLAB 7.10 (R2010a) and Kubuntu 12.10.

Digna
  • 882
  • 5
  • 25

1 Answers1

7

It appears that boxplot makes the axes grow wider, not sure why. In any case, saving the axes position right before plotting and resetting it right after seems to work for me:

Z = normrnd(1,3,[100,1]);
plot(handles.axes1, Z);
pos = get(handles.axes2, 'position');
boxplot(handles.axes2,Z);
set(handles.axes2, 'position', pos);

Cheers, Giuseppe

Giuseppe
  • 5,188
  • 4
  • 40
  • 37
  • Thanks. It doesn't explain why boxplot changes my axes position, but it works, so I guess that's enough :) – Digna Mar 06 '13 at 10:48
  • boxplot is a complex, high-level command (over 4000 lines of code!). As much as I usually dislike this type of workaround, in this case I would just try and see if other problems pop up down the line. Cheers – Giuseppe Mar 07 '13 at 07:58