Use copyUIAxes() to copy plots in AppDesigner or any UIAxes onto regular axes which can be easily saved, printed, or modified.
copyUIAxes copies all children and most properties of a UIAxes to regular axes. If the UIAxes has a legend or colorbar, they can be recreated in the new axes, too.
copyUIAxes(ax) creates a new figure and copies the UIAxes (ax) content to the new figure.
copyUIAxes(ax, destination) copies the UIAxes to the destination which can be a figure or axis handle.
copyUIAxes(ax, 'copyPosition', true) will copy the position properties so the copied axes have the same position relative to the figure as the UIAxes or App.
See the file's help section and the demo document for other optional inputs and demos.
In r2020a Matlab released exportgraphics() and copygraphics() which can be used to copy uiaxes and uifigures which makes parts of copyUIAxes() obsolete.
For discussion on this topic:
Adam Danz (2020). copyUIAxes (https://www.mathworks.com/matlabcentral/fileexchange/73103-copyuiaxes), MATLAB Central File Exchange. Retrieved .
Very well done! Works perfectly! Thank you for your time and effort :)
Thank u,copytuiaxes() is perfect. When i use the copygraphics() to copy my uiaxes, but only copy to clipboard, not a new figure for modifying.
@Lisa Månsson, I've been considering an option to copy axes positions and have already implemented it but I need more time for testing so check back for updates in a few days. Be sure to "follow" this page so you get can a notification when the function updates. In the meantime, here's a demo you can run on your machine and adapt to your needs. Replace the handles with your object handles. If you have further questions, please use the [Contact] button on my profile page to write to me rather than using this ratings section for discussion.
fh = uifigure();
uiax = uiaxes(fh);
C = imread('ngc6543a.jpg');
h = copyUIAxes(uiax);
h.axes.Units = uiax.Units
h.axes.Position = uiax.InnerPosition;
Do you know of a simple way to make the pixel size of the figure the same as in the appGUI's axis from where I take it?
I tried different options but haven't found a solution yet. I did not get it working using exportgraphics in combo with tiledlayout. Using imresize I'm scared of modifying the image since there is interpolation involved and I don't think it should be nessecary when my original appGUI-figure is of the pixel size I want.
Apart from that, great function. Finally I get the background included when I save the figure. Thank you
@Dovletgeldi Seyitliyev, thanks for the rating & feedback. There are several properties that are not copied from the UIAxes. Some of the properties such as the position properties are intentionally not copied because they would cause problems. Other properties are not copied because they are read-only. When calling copyUIAxes(), you can set 'listIgnoredProps' to true to print to the command window a table of graphics object properties that were not copied. The current version of copyUIAxes (vs 2.0) should have the same behavior as earlier versions. If you have found an exception to that or if you have a feature request, please PM me using the [Contact] button in my profile. I'd rather not turn this comment section into a discussion. Thanks again.
Thanks, it was handy to copy uifigure to normal figure and then "decorate" your figure for your needs there using plot tools, it was not just to copy figure,
Do you think there is workaround to achieve same thing that was working before ?
@Dovletgeldi Seyitliyev, yes, the latest vs 2.0.0 is compatible with r2020a.
Does it work for 2020a
Thank you, excellent function.
I just used this function to copy an App Designer plot to a figure window so I could use the print statement to save it to a .png file. The function worked beautifully and was easy to add to my project. Many thanks to Adam.
@Rohit Deshmukh, see the link below for a discussion on this matter.
Cannot use this function, if XAxisTickLabels are cell array. Getting this error "Value must be a vector of type single or double whose values increase".
Please help to fix this
Served my purpose perfectly. Easy to use and well documented.
Exactly what I need! Many thanks for sharing this program.
If your goal is to save a figure and reload it later, here it is how to do it:
% Save it:
newFig = figure();
figHandle = copyUIAxes(app.UIAxes, newFig)
% Reload it:
figHandle = openfig('AA.fig');
axHandle = gca(figHandle);
It would be even better if the figure handle can be saved and reloaded without the creation of an independent figure.
Helpful workaround for copying uiaxes to axes object for the purpose of printing. I appreciate the options for legend and colorbar.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!