This example shows two approaches for saving only the axes from a figure that has UI
controls. First, the example shows how to use
'-noui' option. Then, the example shows how to copy the axes to a
new figure and save the new figure instead.
Alternatively, you can interactively save only the axes from a figure using the export button in the axes toolbar. The toolbar appears when you hover over the axes. When you save axes using the export button, the saved output is tightly cropped around the axes content, including any legends or colorbars. The output does not include content that is not related to the axes, such as UI controls or other axes in the figure.
To create an example of a figure with UI controls, set your current folder to one to which you have write access. Then, copy this example code.
To save the figure and exclude the UI controls from the saved output, use
'-noui' option, then
To maintain the current figure background color in the saved figure, set the
InvertHardcopy property of the figure to
'off'. Otherwise, the saved figure has a white background.
Starting in R2014b, you can use dot notation to set properties. If you are using an
earlier release, use the
set function instead.
fig = gcf; fig.InvertHardcopy = 'off'; print('PlotWithoutUIControls','-dpng','-noui')
To eliminate the blank space, copy the axes to a new figure and resize the axes
to fill the figure. For example, click the axes to make it the current axes. Use
copyobj to copy it to a new figure. Then, set the
Position property of the new axes to fill the figure.
ax_old = gca; f_new = figure; ax_new = copyobj(ax_old,f_new) set(ax_new,'Position','default')
Save the new figure using either