File Exchange

image thumbnail


version 4.0.1 (193 KB) by Adam Danz
Copy UIAxes (eg. AppDesigner) and most properties to a new figure and recreate the legend and colorbar if they exist.


Updated 17 Mar 2021

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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:

Cite As

Adam Danz (2021). copyUIAxes (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (27)

Adam Danz

Thank you @Thade Hobbensiefken. Footnote [17] within the copyUIAxes.m file (vs 4.0) also addresses this issue. I'll include a solution to this in the next release.

Thade Hobbensiefken

Thank yo very much for this great function!
I had problems to copy axes with datetime rulers for the X-Axis but could solve it by generating a axis with a datetime ruler for my own and pass this as destination:

ax = axes()
if isa(uiAxis.XAxis,'')


Spot on ! Excellent function.

Rudy Fink

Stuart Scollay

Ivan Duque Camacho

Uththama Kajan

Very well done! Works perfectly! Thank you for your time and effort :)

Max Wollgarten

Smile bag

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.

Robert Hunter

Adam Danz

@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;

Lisa Månsson

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

Adam Danz

@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 ?

Adam Danz

@Dovletgeldi Seyitliyev, yes, the latest vs 2.0.0 is compatible with r2020a.

Does it work for 2020a


Thank you, excellent function.

Hye-mi Jeong

Hope Q

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.

Chang hsiung

Rohit Deshmukh

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

Md. Rahman

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)
savefig(figHandle, 'AA.fig');

% Reload it:
figHandle = openfig('AA.fig');
axHandle = gca(figHandle);
copyobj(axHandle.Children, app.UIAxes)

It would be even better if the figure handle can be saved and reloaded without the creation of an independent figure.

Hope Q

Helpful workaround for copying uiaxes to axes object for the purpose of printing. I appreciate the options for legend and colorbar.

Hope Q

MATLAB Release Compatibility
Created with R2019b
Compatible with R2016a to R2020b
Platform Compatibility
Windows macOS Linux

Inspired by: export_fig

Inspired: BoxPlotPro, Phase Portrait Plotter

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!