MATLAB: Do the axis resize when I add points to an existing axis after creating a legend in MATLAB 7.0.1 (R14 SP1)

axislegendMATLABplotre-sizeresize

I created a plot and then added the legend to the plot. I then set the "Units" property of the figure and its children to "normalized". The list has a "ButtonDownFcn" callback function "addpoint" which adds a point to the plot. When I click on the figure, a point is added but the axis gets resized. This resizing behavior is not observed under the following two scenarios.
1. This behavior is not observed if the legend is not added to the plot.
2. With the legend added, the resizing behavior is not observed when I specify a "ResizeFcn" callback function "resizeFigure" for the figure and inside this call back reset the axis "Position" property. I noted that this callback function gets called when the "Units" are set to "normalized".
This behavior is also observed in R14SP2. This is NOT observed in R14. However, in R14, the placement of the legend is wrong.

Best Answer

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
We have verified that there is a bug in MATLAB 7.0.1 (R14 SP1) and MATLAB 7.0.2 (R14 SP2) that causes the figure to resize when the figure contains a "legend" and points are added to the plot.
To work around this issue, in the "addpoint" callback function, before plotting the point get the axis position property and after plotting the point reset the position property. The modified "addpoint" function is as follows:
function addpoint(varargin)
ha= gca;
% plot random point
hold on;
pos = get(ha,'Position'); % added code

plot(rand(1)*90+5,rand(1)*0.9+0.05,'ro ','MarkerSize',10);
set(ha,'Position',pos) % added code
hold off;