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
- 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. - Name it.
f2 = figure(Name="Residuals");uses thefigure(Name=Value)form. The window title is the figure number followed by the name. SetNumberTitleorIntegerHandleto'off'to show only the name. - Size and place it. The
Positionproperty is[left bottom width height]in the units given byUnits; the default is pixels, and normalized, inches, centimeters, points and characters are also accepted. SettingPositionon a docked figure undocks it. Example:f2.Position = [100 100 600 400]; - Switch to a figure.
figure(f1)makes the figure with handlef1the current figure and brings it to the front.figure(2)makes the figure whose Number is 2 current, or creates it if none exists.gcfreturns the current figure. - 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. - Set the background colour if needed.
Coloraccepts 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
- 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.savefigappends.figand accepts no other extension. - Choose a version (R2024b and later). Pass a third argument:
savefig(f1,"MyFile.fig","-v7.3"). - Reopen.
openfig("MyFile.fig")opens the file;myfigs = openfig("TwoFiguresFile.fig")returns the Figure objects. You can also useopen.
| 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 withfigure(f1), before plotting. close allleft a window open. Its handle is probably hidden. Useclose all hidden, orclose all forceif aCloseRequestFcnblocks closing.- Position change undocked the window. This is documented: setting
Positionon a docked figure undocks it. - Transparent background looks black.
Colorset to'none'prints as transparent but displays black. - A
.figfile will not open in another program. FIG-files open only in MATLAB, throughopenfigoropen. savefigrejected a file name. Only the.figextension 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
- MathWorks, figure, read 2026-11-08.
- MathWorks, close, read 2026-11-08.
- MathWorks, savefig, read 2026-11-08.
- GNU Octave manual, Multiple Plot Windows, read 2026-11-08.
- Matplotlib, matplotlib.pyplot.figure, read 2026-11-08.







