Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

figure

Create figure window

Syntax

figure
figure(Name,Value)
f = figure(___)
figure(f)
figure(n)

Description

figure creates a new figure window using default property values. The resulting figure is the current figure.

example

figure(Name,Value) modifies properties of the figure using one or more name-value pair arguments. For example, figure('Color','white') sets the background color to white.

example

f = figure(___) returns the Figure object. Use f to query or modify properties of the figure after it is created.

example

figure(f) makes the figure specified by f the current figure and displays it on top of all other figures.

figure(n) finds a figure in which the Number property is equal to n, and makes it the current figure. If no figure exists with that property value, MATLAB® creates a new figure and sets its Number property to n.

Examples

collapse all

Create a figure, and specify the Name property. By default, the resulting title includes the figure number.

figure('Name','Measured Data');

Specify the Name property again, but this time, set the NumberTitle property to 'off'. The resulting title does not include the figure number.

figure('Name','Measured Data','NumberTitle','off');

Create two figures, and then create a line plot. By default, the plot command targets the current figure.

f1 = figure;
f2 = figure;
plot([1 2 3],[2 4 6]);

Set the current figure to f1, so that it is the target for the next plot. Then create a scatter plot.

figure(f1);
scatter((1:20),rand(1,20));

Input Arguments

collapse all

Target figure, specified as a Figure object.

Target figure number, specified as a scalar integer value. When you specify this argument, MATLAB searches for an existing figure in which the Number property is equal to n. If no figure exists with that property value, MATLAB creates a new figure and sets its Number property to n. By default, the Number property value is displayed in the title of the figure.

Data Types: double

Name-Value Pair Arguments

Example: figure('Color','white') creates a figure with a white background.

    Note:   The properties listed here are only a subset. For a full list, see Figure Properties.

collapse all

This property is read-only.

Figure number, returned as an integer or empty array. You can refer to a figure using this value. For example, figure(2) makes the figure with a Number property value of 2 the current figure.

If the IntegerHandle property is set to 'off', Number is an empty array.

If IntegerHandle is 'on', the Number property value is an integer. If the Figure object is deleted, MATLAB reuses the number for the next figure.

Figure name, specified as a character vector.

Example: figure('Name','Results') sets the figure name to 'Results'.

By default, the name is 'Figure n', where n is an integer. When you specify the Name property, the title of the figure becomes 'Figure n: name'. If you want only the Name value to appear, set IntegerHandle or NumberTitle to 'off'.

Background color, specified as an RGB triplet, a predefined color name, or 'none'. If you specify 'none', the background color appears black on screen, but if you print the figure, the background prints as though the figure window is transparent.

An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7]. This table lists the long and short color name options and the equivalent RGB triplet values.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black''k'[0 0 0]

Data Types: double | char

Location and size of the drawable area, specified as a vector of the form [left bottom width height]. This area excludes the figure borders, title bar, menu bar, and tool bars.

This table describes each element in the Position vector.

ElementDescription
leftDistance from the left edge of the primary display to the inner left edge of the figure window. This value can be negative on systems that have more than one monitor.

If the figure is docked, then this value is relative to the Figure panel within the MATLAB desktop.
bottomDistance from the bottom edge of the primary display to the inner bottom edge of the figure window. This value can be negative on systems that have more than one monitor.

If the figure is docked, then this value is relative to the Figure panel within the MATLAB desktop.
widthDistance between the right and left inner edges of the figure.
heightDistance between the top and bottom inner edges of the figure.

All measurements are in units specified by the Units property.

You cannot specify the figure Position property when the figure is docked.

To place the full window, including the borders, title bar, menu bar, tool bars, use the OuterPosition property.

    Note:   The Windows® operating system enforces a minimum window width and a maximum window size. If you specify a figure size outside of those limits, the displayed figure will conform to the limits instead of the size you specified.

Units of measurement, specified one of the values from this table.

Units ValueDescription
'pixels' (default)

Pixels.

Starting in R2015b, distances in pixels are independent of your system resolution on Windows and Macintosh systems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • On Macintosh systems, a pixel is 1/72nd of an inch.

On Linux® systems, the size of a pixel is determined by your system resolution.

'normalized'These units are normalized with respect to the parent container. The lower-left corner of the container maps to (0,0) and the upper-right corner maps to (1,1).
'inches'Inches.
'centimeters'Centimeters.
'points'Points. One point equals 1/72nd of an inch.
'characters'

These units are based on the default uicontrol font of the graphics root object:

  • Character width = width of the letter x.

  • Character height = distance between the baselines of two lines of text.

To access the default uicontrol font, use get(groot,'defaultuicontrolFontName') or set(groot,'defaultuicontrolFontName').

MATLAB measures all units from the lower left corner of the parent object.

This property affects the Position property. If you change the Units property, consider returning its value to the default value after completing your computation to avoid affecting other functions that assume the default value.

The order in which you specify the Units and Position properties has these effects:

  • If you specify the Units before the Position property, then MATLAB sets Position using the units you specify.

  • If you specify the Units property after the Position property, MATLAB sets the position using the default Units. Then, MATLAB converts the Position value to the equivalent value in the units you specify.

More About

collapse all

Current Figure

The current figure is the target for graphics commands such as axes and colormap. Typically, it is the last figure created or the last figure clicked with the mouse. The gcf command returns the current figure.

See Also

Functions

Properties

Introduced before R2006a

Was this topic helpful?