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 (2023). copyUIAxes (https://www.mathworks.com/matlabcentral/fileexchange/73103-copyuiaxes), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired by: export_fig
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Fixed error with Matlab version check in r2021a.
Now supports yyaxis plots & copies subtitles. PositionConstraint no longer copied.
copyPosition input added to copy the axes position within the figure. Other minor changes.
Updated release compatibility fields; no changes to code.
Updated for changes made to Matlab r2020a
Announcement: Update for r2020a coming soon.
Now works with categoricalHistograms; new warning message appears if there's a problem copying a property; drawnow() added prior to copying; axis visibility is set at the end only when the UIAxis visibility is 'on'.
Changed thumbnail image only.
Destination figure handle returned in output structure; improved error handling; improved listIgnoredProps text.
Edited description; no change to code.