UIFigure / UIAxes support doesn't work
adamdanz opened this issue · 2 comments
TL;DR: copyobj() cannot be used to copy UIAxes (as of r2019b).
As discussed here in Matlab Central forum, the changes recently made to support UIFigure & UIAxes doesn't work. When a UIFigure is supplied as an input, the code searches for its children and uses copyobj() to copy those components to a legacy figure. When a UIAxes is directly supplied as an input, it also uses copyobj() to copy the UIAxes to the legacy figure. The problem is that copyobj() is not supported for UIAxes. As evidence of that,
uax = uiaxes();
fig = figure();
copyobj(uax,fig)
% Error using matlab.ui.control.UIAxes/copyElement
%Functionality not supported with UIAxes. For more information,
% see Graphics Support in App Designer.
The error is not thrown in export_fig() because copyobj() is called from a try/catch that rethrows the error as a modified warning.
Otherwise, export_fig() is terrific!
I recently wrote a function copyUIAxes() that searches for and copies the children of a UIAxes to a new legacy axes along with the legend and colorbar if they exist. I think this is the only workaround to using copyobj() with UIAxes.
uiaxes cannot be copied if it is created via the uiaxes() function, but it can indeed be copied if it is created via the legacy axes() function, even when it is in the uifigure:
fig = figure('Name','Legacy figure');
uif = uifigure('Name','uifigure');
uax = axes(f); % uiaxes created in the uifigure using the legacy axes() function
hln = contourf(uax, peaks);
hlg = legend(uax);
drawnow;
copyobj(uax, fig) % works perfectly ok, no error
I'll investigate to check what makes the axes created in uifigure via axes() or uiaxes() so different.
Yeah, this problem only pertains to copying UIAxes. I'll certainly be interested in what you find! Thanks for all of your contributions, Yair.