Skip to main content
v2026.11,858 entries · CC-BY 4.0

MATLAB Figures: Create, Name, Switch, Close and Save Figure Windows

How to create, name, switch, close and save MATLAB figure windows, with a close-command table and .fig version options.

Written and maintained by CASRAI Editorial Board

Last updated

Who this is for: researchers and analysts who work with several MATLAB figure windows at once and need to create, name, switch between, close and save them reliably. For what goes inside a figure, see the sibling pages on MATLAB graphing, subplots, plot labels and line styles; this page covers the figure window itself.

A MATLAB figure is the window (a Figure object) that holds your axes and graphics. figure creates a new one, figure(n) makes figure number n current (creating it if it does not exist), close removes it, and savefig stores it as a .fig file that only MATLAB can reopen. Syntax below follows the MathWorks reference pages for figure, close and savefig, read 2026-11-08.

What MATLAB figures are used for in research

Every MATLAB plot is drawn into a figure. In a research workflow the figure is the unit you create per result, keep open while you compare runs, and save so that the plot can be edited later. Managing figures deliberately, by handle or by number, stops a script from drawing a new plot over an old one or leaving dozens of windows open.

Install or access

MATLAB is a MathWorks product; obtain and activate it only from MathWorks or through your institution’s licence. Setup and licence types are covered in MATLAB installation and MATLAB licensing. For an overview of what the software does, see what MATLAB is used for.

Create, number, name and switch figures

Step-by-step: working with several figures

  1. Create a figure and keep its handle. f1 = figure; opens a new figure window with default properties and returns the Figure object, which you can query or modify after creation.
  2. Name it. f2 = figure(Name="Residuals"); uses the figure(Name=Value) form. The window title is the figure number followed by the name. Set NumberTitle or IntegerHandle to 'off' to show only the name.
  3. Size and place it. The Position property is [left bottom width height] in the units given by Units; the default is pixels, and normalized, inches, centimeters, points and characters are also accepted. Setting Position on a docked figure undocks it. Example: f2.Position = [100 100 600 400];
  4. Switch to a figure. figure(f1) makes the figure with handle f1 the current figure and brings it to the front. figure(2) makes the figure whose Number is 2 current, or creates it if none exists. gcf returns the current figure.
  5. Plot into the current figure. Graphics commands draw into the current figure, so call figure(f1) before plotting if another window may have taken focus.
  6. Set the background colour if needed. Color accepts an RGB triplet, a hex colour code or a colour name. The value 'none' prints as transparent but appears black on screen.

Handles or numbers?

Approach Syntax Source behaviour
Handle f = figure; ... figure(f) f is the Figure object returned by figure; figure(f) makes it current and on top.
Number figure(3) Makes the figure with Number 3 current, or creates it when none exists.
Current figure gcf Returns the current figure.

Close figures

Command Effect (MathWorks close reference)
close Same as close(gcf): closes the current figure.
close(fig) Closes the figure given by the handle.
close force Closes the figure even if its CloseRequestFcn would block closing.
close all Closes all figures whose handles are visible.
close all hidden Also closes figures with hidden handles.
close all force Closes all figures even when a CloseRequestFcn blocks closing.
status = close(___) Returns 1 if the figure closed and 0 otherwise.

A hidden handle is a figure whose HandleVisibility is 'callback' or 'off'; plain close all skips those.

Save and reopen .fig files

  1. Save. savefig("MyFile.fig") saves the current figure; savefig(f1,"MyFile.fig") saves a specific figure. The first argument may be an array of figures, which stores them all in one file. savefig appends .fig and accepts no other extension.
  2. Choose a version (R2024b and later). Pass a third argument: savefig(f1,"MyFile.fig","-v7.3").
  3. Reopen. openfig("MyFile.fig") opens the file; myfigs = openfig("TwoFiguresFile.fig") returns the Figure objects. You can also use open.
Version option Documented meaning
"-v7.3" Supports files larger than 2 GB.
"-v7" Compressed; up to 2 GB; supports Unicode.
"-v6" Older option listed on the savefig reference page.

The reference page states that FIG-files are compatible with R2014b and later and can be opened only in MATLAB. The "compact" option is deprecated. To save only part of a figure, use save to a MAT-file instead. Related: saving data in MATLAB.

Output and how to read it

The Figure object returned by figure carries the properties named above: Number (used by figure(n)), Name, Position, Units and Color. Displaying f at the command line lists them. The window title shows the number and name, unless NumberTitle or IntegerHandle is 'off'. status = close(f1) gives 1 or 0, which a script can test.

Troubleshooting

  • A new plot overwrote an old one. Graphics commands draw into the current figure. Create a separate figure with figure, or switch with figure(f1), before plotting.
  • close all left a window open. Its handle is probably hidden. Use close all hidden, or close all force if a CloseRequestFcn blocks closing.
  • Position change undocked the window. This is documented: setting Position on a docked figure undocks it.
  • Transparent background looks black. Color set to 'none' prints as transparent but displays black.
  • A .fig file will not open in another program. FIG-files open only in MATLAB, through openfig or open.
  • savefig rejected a file name. Only the .fig extension is supported.

Free alternatives

Tool Equivalent of figure(n) (from its own documentation)
GNU Octave figure(n): if no figure with that number exists, a new one is created; if it exists, it is made visible and becomes the current figure for plotting (Octave manual, multiple plot windows, read 2026-11-08).
Python Matplotlib matplotlib.pyplot.figure(num=...): num is a unique identifier; if a figure with that identifier exists it is made active and returned (Matplotlib 3.11.2 documentation, read 2026-11-08).

FAQ

How do I open a new figure in MATLAB?

Run figure. It opens a new figure window with default properties; f = figure also returns the Figure object so you can change its properties later.

How do I switch between figures?

Use figure(f) with a saved handle, or figure(n) with the figure’s number. Either makes that figure current.

How do I close every figure?

close all closes figures with visible handles; add hidden or force for hidden handles or figures that block closing.

Can I save several figures in one file?

Yes. savefig accepts an array of figures as its first argument and stores them in one .fig file.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about MATLAB Figures: Create, Name, Switch, Close and Save Figure Windows

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →