Axis overlap in GUI when constructing a box in MATLAB

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

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

Then in OpeningFcn add the following lines:

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

Then lauch GUI. I see the following:

GUI when launching the program

As you can see, the two axes overlap. I tried changing the properties of the window field, but no luck.

I am using MATLAB 7.10 (R2010a) and Kubuntu 12.10.

+4
source share
1 answer

It seems that boxplot makes the axes wider without knowing why. In any case, preserving the position of the axes right before applying and dropping it right after it 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

+7
source

All Articles