savefig

Saves a figure, with all of its graphics objects, to a .fig file.

Category: Graphics > Printing and Saving

Syntax

savefig(filename)

Saves the current figure to filename.

savefig(h, filename)

Saves the figure with handle h.

Description

A .fig file keeps a figure as a set of objects (axes, lines, bars, labels and their properties) instead of as a picture, so the figure can be opened again with openfig and edited, rather than just viewed.

Use it to hand someone a plot they can still change, or to store a figure and reload it in a later session. To get an image for a document, use exportgraphics or saveas instead.

Input arguments

h
Handle of the figure to save. When omitted, the current figure is used.
filename
File name as text. The .fig extension is added when the name has none.

Example

Save a plot and open it again

f = figure('Visible', 'off');
plot(1:4, (1:4).^2);
savefig(f, 'squares');
close(f);
g = openfig('squares', 'invisible');
l = findobj(g, 'Type', 'line');
disp(get(l, 'YData'))
Output
     1     4     9    16

See also

openfig hgsave hgload saveas exportgraphics