Control appearance and behavior of figure window (2024)

Table of Contents
Window Appearance MenuBar — Figure menu bar display 'figure' (default) | 'none' ToolBar — Figure toolbar display 'auto' (default) | 'figure' | 'none' DockControls — Interactive figure docking 'on' (default) | 'off' WindowState — Window state 'normal' (default) | 'minimized' | 'maximized' | 'fullscreen' Position and Size InnerPosition — Location and size of drawable area [left bottom width height] OuterPosition — Location and size of outer bounds [left bottom width height] Clipping — Clipping of child components (not recommended) 'on' (default) | on/off logical value Resize — Resizable figure 'on' (default) | on/off logical value Plotting Colormap — Color map for axes content of figure parula (default) | m-by-3 array of RGB triplets Alphamap — Transparency map for Axes content array of 64 values from 0 to 1 (default) | array of finite alpha values from 0 to 1 NextPlot — Directive on how to add next plot 'add' (default) | 'new' | 'replace' | 'replacechildren' Renderer — Renderer 'opengl' (default) | 'painters' RendererMode — Renderer selection 'auto' (default) | 'manual' GraphicsSmoothing — Axes graphics smoothing 'on' (default) | on/off logical value Printing and Exporting PaperPosition — Figure size and location on page when printing or saving four-element vector of the form [left bottom width height] PaperPositionMode — Directive to use displayed figure size when printing or saving 'auto' (default) | 'manual' PaperSize — Custom page size two-element vector of the form [width height] PaperUnits — Units used for PaperSize and PaperPosition'inches' | 'centimeters' | 'normalized' | 'points' PaperOrientation — Orientation of page 'portrait' (default) | 'landscape' PaperType — Standard page sizes 'usletter' | 'uslegal' | 'tabloid' | 'a0' | 'a1' | 'a2' | 'a3' | ... InvertHardcopy — Figure background color when printing or saving 'on' (default) | on/off logical value Mouse Pointer Pointer — Pointer symbol 'arrow' (default) | 'ibeam' | 'crosshair' | 'watch' | 'topl' | 'custom' | ... PointerShapeCData — Custom pointer symbol 16-by-16 matrix (default) | 32-by-32 matrix PointerShapeHotSpot — Active pixel of pointer [1 1] (default) | two-element vector Interactivity Visible — State of visibility'on' (default) | on/off logical value CurrentAxes — Target axes in current figure Axes object | PolarAxes object | graphics object CurrentObject — Current object child object of figure CurrentPoint — Current point two-element vector CurrentCharacter — Current character '' (default) | character SelectionHighlight — Display of selection handles (not recommended) 'on' (default) | on/off logical value SelectionType — Mouse selection type 'normal' (default) | 'extend' | 'alt' | 'open' ContextMenu — Context menu empty GraphicsPlaceholder array (default) | ContextMenu object Common Callbacks ButtonDownFcn — Button down callback '' (default) | function handle | cell array | character vector Keyboard Callbacks KeyPressFcn — Key-press callback '' (default) | function handle | cell array | character vector KeyReleaseFcn — Key-release callback '' (default) | function handle | cell array | character vector Window Callbacks CloseRequestFcn — Close request callback 'closereq' (default) | function handle | cell array | character vector SizeChangedFcn — Size changed callback '' (default) | function handle | cell array | character vector WindowButtonDownFcn — Window button down callback '' (default) | function handle | cell array | character vector WindowButtonMotionFcn — Window button motion callback '' (default) | function handle | cell array | character vector WindowButtonUpFcn — Window button-up callback '' (default) | function handle | cell array | character vector WindowKeyPressFcn — Window key-press callback '' (default) | function handle | cell array | character vector WindowKeyReleaseFcn — Window key-release callback '' (default) | function handle | cell array | character vector WindowScrollWheelFcn — Window scroll wheel callback '' (default) | function handle | cell array | character vector Callback Execution Control HitTest — Ability to become current object 'on' (default) | on/off logical value Parent/Child Parent — Figure parent root object Children — Children of figure empty GraphicsPlaceholder array (default) | 1-D array of objects HandleVisibility — Visibility of figure object 'on' (default) | 'callback' | 'off' Identifiers NumberTitle — Use number title 'on' (default) | on/off logical value IntegerHandle — Use integer handle 'on' (default) | on/off logical value FileName — File name character vector | string scalar Type — Type of Figure object 'figure' Version History R2023b: GraphicsSmoothing property will be removed in a future release R2022a: Renderer and RendererMode properties will have no effect in a future release R2020a: UIContextMenu property is not recommended R2016a: PaperPositionMode default value changed to 'auto' See Also Topics MATLAB Command Americas Europe Asia Pacific References

Control appearance and behavior of figure window

expand all in page

Figures are containers for graphics or user interface components. Figure properties control the appearance and behavior of a particular instance of a figure. To modify aspects of a figure, change property values. Use dot notation to query and set properties.

f = figure;u = f.Units;f.Units = 'inches';

For figures created with the uifigure function, see UI Figure Properties instead.

Window Appearance

expand all

Figure menu bar display, specified as 'figure' or 'none'. The MenuBar property enables you to display or hide the default menus at the top of a figure window. Specify 'figure' to display the menu bar. Specify 'none' to hide it.

This property affects only default menus, and does not affect menus defined with the uimenu command.

Menu bars do not appear in figures whose WindowStyle property is set to 'Modal'. If a figure containing uimenu children is changed to 'Modal', the menu children still exist in the Children property of the figure. However, the menus do not display while WindowStyle is set to 'Modal'.

Note

If you do not want to display the default menus in the figure, then set this property to 'none' when you create the figure.

Figure toolbar display, specified as one of the following:

  • 'auto' — Uses the same value as the MenuBar property.

  • 'figure' — Toolbar displays.

  • 'none' — Toolbar does not display.

This property affects only the default toolbar. It does not affect other toolbars such as, the Camera Toolbar or Plot Edit Toolbar. Selecting Figure Toolbar from the figure View menu sets this property to 'figure'.

Toolbars do not appear in figures whose WindowStyle property is set to 'Modal'. If a figure containing a toolbar is changed to 'Modal', the tool bar children still exist in the Children property of the figure. However, the toolbar does not display while WindowStyle is set to 'Modal'.

Note

If you want to hide the default tool bar, then set this property to 'none' when you create the figure.

Interactive figure docking, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Figure can be docked in the MATLAB® desktop. The Desktop > Dock Figure menu item and the Dock Figure button Control appearance and behavior of figure window (1) in the menu bar are enabled.

  • 'off' — MATLAB disables the Desktop > Dock Figure menu item and does not display the figure dock button.

    You cannot set the DockControls property to 'off' if the WindowStyle is set to 'docked'.

Setting the DockControls property is not supported in MATLAB Online™.

Window state, specified as one of these values:

  • 'normal' — The window displays in a normal state.

  • 'minimized' — The window is collapsed, but you can still execute commands to get or set its properties, to add children, or to create plots in the window.

  • 'maximized' — The window fills the screen. The minimize, restore, and close buttons provided by the operating system appear in the corner of the window. If the window has menus and tool bars in the normal state, they are present in this state.

  • 'fullscreen' — The window fills the screen. However, the minimize, restore, and close buttons provided by the operating system are hidden. If the window has menus and tool bars in the normal state, they are present in this state.

Clicking the minimize, maximize, or restore button provided by the operating system sets the WindowState property accordingly. Pressing Ctrl+F11 (Windows® and Linux®) or Ctrl+Command+f (macOS) toggles the 'fullscreen' state.

Setting the WindowState property on a docked figure or in MATLAB Online is not supported.

Position and Size

expand all

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. All measurements are in units specified by the Units property.

This property value is identical to the Position property value.

Location and size of the outer bounds, specified as a vector of the form [left bottom width height]. This property defines the region enclosed by the figure’s outer bounds (which includes the borders, title bar, menu bar, and tool bars).

This table describes each element in the vector.

ElementDescription
leftDistance from the left edge of the primary display to the outer 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 outer 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 outer edges of the figure.
heightDistance between the top and bottom outer edges of the figure.

All measurements are in units specified by the Units property.

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

Note

The Windows operating system enforces a minimum windowwidth and a maximum window size. If you specify a figure size outsideof those limits, the displayed figure will conform to the limits insteadof the size you specified.

This property has no effect on figures.

Resizable figure, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

When this property is set to 'on', the figure is resizable. Otherwise, it is not resizable.

Plotting

expand all

Color map for axes content of a figure, specified as an m-by-3 array of RGB (red, green, blue) triplets that define m individual colors.

Example: figure('Colormap',[1 0 1; 0 0 1; 1 1 0]) sets the color map to three colors: magenta, blue, and yellow.

MATLAB accesses these colors by their row number.

Color maps affect the rendering of objects created with the surface, image, and patch functions, but generally do not affect other graphics objects.

When you set the Colormap property of the figure, then axes and charts in the figure use the same colormap.

Transparency map for Axes content, specified as an array of finite alpha values that progress linearly from 0 to 1. The size of the array can be m-by-1 or 1-by-m. MATLAB accesses alpha values by their index in the array. Alphamaps can be any length.

Alphamaps affect the rendering of objects created with the surface, image, and patch functions, but do not affect other graphics objects.

When you set the Alphamap property of the figure, then axes and charts in the figure use the same alpha map.

Directive on how to add next plot, specified as 'add', 'new', 'replace', or 'replacechildren'.

This table describes the effects of each value.

Property ValueEffect
'new'

Creates a new figure and uses it as the current figure.

'add'

Adds new graphics objects without clearing or resetting the current figure.

'replacechildren'

Removes all axes objects who are not hidden before adding new objects. Does not reset figure properties.

Equivalent to using the clf command.

'replace'

Removes all axes objects and resets figure properties to their defaults before adding new graphics objects.

Equivalent to using the clf reset command.

Consider using the newplot function to handle the NextPlot property. For more information, see the axes NextPlot property and Prepare Figures and Axes for Graphs.

Renderer for screen display and printing, specified as one of these values:

  • 'opengl' — OpenGL® renderer. This option enables MATLAB to access graphics hardware if it is available on your system. The OpenGL renderer displays objects sorted in front to back order, as seen on the monitor. Lines always draw in front of faces when at the same location on the plane of the monitor.

  • 'painters' — Painters renderer. This option works well for axes in a 2-D view. In 2-D, the Painters renderer sorts graphics objects by child order (order specified). In 3-D, the Painters renderer sorts objects in front to back order. However, it might not correctly draw intersecting polygons in 3-D.

Note

The Renderer property will be removed in a future release. For more information, see Version History.

Setting the Renderer property is not supported in MATLAB Online.

OpenGL Hardware and Software Implementations

OpenGL is available on all computers that run MATLAB since a software version of OpenGL is built-into MATLAB. However, if you have graphics hardware that supports a hardware-accelerated version of OpenGL, then MATLAB automatically uses the hardware-accelerated version to increase performance.

In some cases, MATLAB automatically uses software OpenGL even if a hardware version is available. For example, MATLAB uses the software version if it detects graphics hardware with known driver issues or detects that you are using a virtual machine or remote desktop on Windows.

MATLAB issues a warning if it cannot find a usable OpenGL library.

Software OpenGL Selection

To switch from hardware to software OpenGL, do the following:

  • On Linux systems, start MATLAB with the command matlab -softwareopengl.

  • On Windows systems, execute the command opengl software in MATLAB or start MATLAB with the command matlab -softwareopengl.

  • On Macintosh systems, software OpenGL is not supported.

The following software versions are available:

  • On Linux systems, MATLAB uses the software implementation of OpenGL that is included in the MATLAB distribution.

  • On Windows, OpenGL is available as part of the operating system. If you experience problems with OpenGL, contact your graphics driver vendor to obtain the latest qualified version of OpenGL.

  • On Macintosh systems, software OpenGL is not available.

Determine OpenGL Library Version

To determine the version and vendor of the OpenGL library that MATLAB is using on your system, call the rendererinfo function. For example, this command gets the information for the current axes and stores it in a structure called info.

info = rendererinfo(gca)

This structure also provides the name of the graphics renderer in the GraphicsRenderer field. For example, if MATLAB is using hardware-accelerated OpenGL, the field returns 'OpenGL Hardware'. If MATLAB is using software OpenGL, the field returns 'OpenGL Software'.

XServer Connection Lost

When using Linux, if there is a break in the connection to the XServer, MATLAB can crash with a segmentation violation. If this happens, ensure that the system has the latest XServer installed.

On a Linux system, you also can try upgrading the OpenGL driver or starting MATLAB with software OpenGL using this command:

 matlab -softwareopengl

Renderer selection, specified as:

  • 'auto' — MATLAB selects the rendering method for printing and screen display based on the size and complexity of the graphics objects in the figure.

  • 'manual' — MATLAB uses the renderer specified with the Renderer property.

MATLAB sets the RendererMode property to 'manual' if you explicitly set the Renderer property to 'painters' or 'opengl'.

Axes graphics smoothing, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

Smoothing reduces the appearance of jagged lines in an axes graphic. MATLAB applies a smoothing technique to an axes graphic (and the axes rulers) if GraphicsSmoothing is set to 'on', and either of these conditions is true:

  • The Renderer property is set to 'painters'.

  • The Renderer property is set to 'opengl' and your hardware card supports OpenGL.

Graphics SmoothingNo Graphics Smoothing

Control appearance and behavior of figure window (2)

Control appearance and behavior of figure window (3)

(Zoomed-in view)

Control appearance and behavior of figure window (4)

(Zoomed-in view)

Control appearance and behavior of figure window (5)

If your axes graphic contains mostly vertical or horizontal lines, consider setting the GraphicsSmoothing property to 'on' and the line or lines AlignVertexCenters property to 'on'. The smoothing technique sacrifices some sharpness for smoothness, which might be particularly noticeable in such graphics.

Graphics smoothing has no affect on text. MATLAB smooths text regardless of the value of the GraphicsSmoothing property.

Setting the GraphicsSmoothing property is not supported in MATLAB Online.

Note

The GraphicsSmoothing property will be removed in a future release. All graphics will be smooth when the property is removed.

Printing and Exporting

expand all

Figure size and location on page when printing or saving, specified as a four-element vector of the form [left bottom width height].

  • left and bottom values — Control the distance from the lower left corner of the page to the lower left corner of the figure. These values are ignored when saving a figure to a nonpage format, such as a PNG or EPS format.

  • width and height values — Control the figure size. If the width and height values are too large, then the figure might not reach the specified size. If the figure does not reach the specific size, then any UI components on the figure, such as a UI control or a UI table, might not save or print as expected.

The PaperUnits property determines the units of measurement of the PaperPosition values. Consider setting the PaperUnits property to 'normalized'. This setting enables MATLAB to automatically size the figure to occupy the same relative amount of the printed page, regardless of the page size.

Example: figure('PaperPosition',[.25 .25 8 6]) set the figure’s size and location for printing to [.25 .25 8 6].

Directive to use displayed figure size when printing or saving, specified as either 'auto' or 'manual'.

  • 'auto' — Printed or saved figure size matches the displayed figure size. The width and height values of the PaperPosition property equal the figure size on the display. The left and bottom values center the figure. If the figure size changes on the display, the PaperPosition property automatically updates to the appropriate size and location values.

  • 'manual' — Printed or saved figure size might not match the displayed figure size. Use this option if you want to print or save the figure using a size that differs from the display, or if you do not want the figure centered on the printed or saved page. Set the PaperPosition property to the desired size and location. If the figure size changes on the display, the PaperPosition property does not automatically update.

To generate output that has the same size and resolution (DPI) as the displayed figure, set the PaperPositionMode property of the figure to 'auto' and save the figure using print with the -r0 option. The -r0 option ensures that the output resolution is the same as the display resolution. If the resolutions are different, then the generated output size matches the displayed figure size in measured units (inches, centimeters, points), but not in pixels. For example, if the display resolution is 100 DPI, then a 4-by-5 inch figure is 400-by-500 pixels. If the output resolution is 200 DPI, then the printed or saved figure is the same size in inches, but 800-by-1000 pixels.

Custom page size when printing the figure or saving it to a paged format (PDF and PostScript® formats), specified as a two-element vector of the form [width height]. In the United States, the default value is [8.5 11]. In Europe and Asia, the default value is [21 29.7].

Note

If you are saving the figure to a file, the PaperSize property only affects PDF and PostScript file formats. Other file formats ignore this property. Use the PaperPosition property to control the size of the saved figure.

The PaperUnits property determines the units of measurement for the PaperSize property. You cannot set the PaperSize property if the PaperUnits property is set to 'normalized'. Attempting to do so results in an error.

Specifying the PaperSize property sets the PaperType property to the corresponding type, if one exists, or to 'custom' otherwise.

Units used for PaperSize and PaperPosition, specified as one of these values:

  • 'inches' — Value in inches. This is the default when the locale is the United States.

  • 'normalized' — Normalized units. The lower left corner of the page maps to (0,0) and the upper right corner maps to (1,1).

  • 'centimeters' — Value in centimeters. This is the default when the locale is Europe or Asia.

  • 'points' — Value in points. One point equals 1/72 of an inch.

Note

If you change the value of the PaperUnits property, it is good practice to return the property to its original value after completing your computation so as not to affect other functions that assume the PaperUnits property has not changed.

Orientation of page when printing figure or saving it to a paged format (PDF and PostScript formats), specified as one of these values:

  • 'portrait' — Orient the longest page dimension vertically.

  • 'landscape' — Orient the longest page dimension horizontally.

See the orient function for more information.

Note

When using File > Save As, only PDF and full-page PS formats use the PaperOrientation property. Other formats ignore these values.

Standard page sizes when printing the figure or saving it to a paged format (PDF and PostScript formats), specified as one of the values in this table. Specifying the PaperType property sets the PaperSize property to the corresponding page size.

Value

Page Size (Width x Height)

'usletter'

8.5-by-11 in (default in US)

'uslegal'

8.5-by-14 in

'tabloid'

11-by-17 in

'a0'

84.1-by-118.9 cm

'a1'

59.4-by-84.1 cm

'a2'

42-by-59.4 cm

'a3'

29.7-by-42 cm

'a4'

21-by-29.7 cm (default in Europe and Asia)

'a5'

14.8-by-21 cm

'b0'

102.9-by-145.6 cm

'b1

72.8-by-102.8 cm

'b2'

51.4-by-72.8 cm

'b3'

36.4-by-51.4 cm

'b4'

25.7-by-36.4 cm

'b5'

18.2-by-25.7 cm

'arch-a'

9-by-12 in

'arch-b'

12-by-18 in

'arch-c'

18-by-24 in

'arch-d'

24-by-36 in

'arch-e'

36-by-48 in

'a'

8.5-by-11 in

'b'

11-by-17 in

'c'

17-by-22 in

'd'

22-by-34 in

'e'

34-by-43 in

'<custom>'

Custom page size. Specifying a non-standard page size using the PaperSize property sets PaperType to this value.

Figure background color when saving or printing, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Change the figure background and axes background colors to white. Text and other aspects of the figure also might change color to improve the appearance of the generated output.

  • 'off' — Use the same colors as the colors on the display. To change the figure background color on the display, use the Color property of the figure. To change the axes background color, use the Color property of the axes.

Mouse Pointer

expand all

Pointer symbol, specified as one of the values in the following table or as 'custom'. The appearance of the symbol is operating-system dependent.

Value

Resulting Symbol (System Dependent)

'arrow'

Control appearance and behavior of figure window (6)

'ibeam'

Control appearance and behavior of figure window (7)

'crosshair'

Control appearance and behavior of figure window (8)

'watch' (busy system)

Control appearance and behavior of figure window (9)

'topl' or 'botr'

Control appearance and behavior of figure window (10)

'topr' or 'botl'

Control appearance and behavior of figure window (11)

'circle'

Control appearance and behavior of figure window (12)

'cross'

Control appearance and behavior of figure window (13)

'fleur'

Control appearance and behavior of figure window (14)

'left' or 'right'

Control appearance and behavior of figure window (15)

'top' or 'bottom'

Control appearance and behavior of figure window (16)

'hand'

Control appearance and behavior of figure window (17)

Custom Pointer Symbol

To create a custom pointer symbol, programmatically set the Pointer property to 'custom' and use the PointerShapeCData property to define the symbol. See the PointerShapeCData property for more information.

Limitations

Pointer symbols specified by the Pointer property do not display over HTML UI components created with the uihtml function.

Custom pointer symbol, specified as a 16-by-16 matrix (for a 16-by-16 pixel pointer), or as a 32-by-32 matrix (for a 32-by-32 pixel pointer). The figure uses this pointer symbol when you set the Pointer property to 'custom'.

Each element in the matrix defines the brightness level for 1 pixel in the pointer, where the element can have one of these values:

  • 1 — Black pixel.

  • 2 — White pixel.

  • NaN — Transparent pixel, such that underlying screen shows through.

Element (1,1) of the matrix corresponds to the pixel in the upper left corner in the pointer.

Active pixel of the pointer, specified as a two-element vector. The vector contains the row and column indices of a particular element in the PointerShapeCData matrix that corresponds to the desired active pixel. The default value of [1 1] corresponds to the pixel in the upper left corner of the pointer.

If you specify a value outside the range of the PointerShapeCData matrix, then the pointer uses the default active pixel of [1 1] instead.

This property applies only when the Pointer property is set to 'custom'.

Interactivity

expand all

State of visibility, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Display the object.

  • 'off' — Hide the object without deleting it. You still can access the properties of an invisible UI component.

To make your app start faster, set the Visible property to 'off' for all components that do not need to appear at startup.

Changing the size of an invisible container triggers the SizeChangedFcn callback when it becomes visible.

Changing the Visible property of a container does not change the values of the Visible properties of child components. This is true even though hiding the container causes the child components to be hidden.

Target axes in the current figure, specified as an Axes object, a PolarAxes object, or a graphics object such as a HeatmapChart.

In all figures for which axes children exist, there is always a current axes. The current axes does not have to be the topmost axes, and setting an axes to be the current axes does not restack it above all other axes. If a figure contains no axes, the get(gcf,'CurrentAxes') command returns an empty array.

Query the CurrentAxes property to get the current axes object without forcing the creation of an axes if one does not exist.

Current object, returned as a child object of the figure. MATLAB sets the CurrentObject property to the last object clicked in the figure. This object is the front-most object in the view.

The HitTest property of the child object controls whether that object can become the CurrentObject.

Clicking an object whose HandleVisibility property is 'off' sets the CurrentObject property to an empty GraphicsPlaceholder array. To avoid returning the empty array when users click a hidden object, set HitTest property of the hidden object to 'off'.

Use the gco command as an alternative for getting the value of this property.

Current point, returned as a two-element vector. The vector contains the (x, y) coordinates of the mouse pointer, measured from the lower-left corner of the figure. The values are in units specified by the Units property.

The coordinates update when you do any of the following:

  • Press the mouse button within the figure.

  • Release the mouse button after pressing it within the figure.

  • Press the mouse button within the figure, and then release it outside the figure.

  • Rotate the scroll wheel within the figure.

  • Move the mouse within the figure (without pressing any buttons), provided that the WindowButtonMotionFcn property is not empty.

If the figure has a callback that responds to mouse interactions, and you trigger that callback faster than the system can execute the code, the coordinates might not reflect the actual location of the pointer. Instead, they are the location when the callback began execution.

If you use the CurrentPoint property to plot points, the coordinate values might contain rounding error.

Current character, returned as the character of the last key pressed. This property updates when the figure has focus while the user presses a key.

Note

Use of the SelectionHighlight property is not recommended. This property has no effect on figures. This property might be removed in a future release.

Mouse selection type, returned as 'normal', 'extend', 'alt', or 'open'. This property provides information about the last mouse button press that occurred in the figure.

This table lists the possible SelectionType values and the user actions that produce those values.

Value

Corresponding Action

'normal'

Click the left mouse button.

'extend'

Any of the following:

  • Shift-click the left mouse button.

  • Click the middle mouse button.

  • Click both left and right mouse buttons.

'alt'

Either of the following:

  • Control-click the left mouse button.

  • Click the right mouse button.

'open'

Double-click any mouse button.

Context menu, specified as a ContextMenu object created using the uicontextmenu function. Use this property to display a context menu when you right-click on a component.

Common Callbacks

expand all

Button down callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes whenever the user clicks a blank area of the figure.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Specify a Callback Function.

Use the SelectionType property to determine whether the user pressed modifier keys.

Keyboard Callbacks

expand all

Key-press callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user presses a key while the figure or a child object has focus. If the user presses a key on a UIControl or Table component, the callback does not execute unless the Enable property is set to 'off' or 'inactive'.

If the user presses multiple keys at approximately the same time, MATLAB detects all the keys.

The KeyPressFcn callback can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of this object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that appears as a result of pressing the key or keys.

Pressing certain keys or modifying keys with the Ctrl key might return unprintable characters in this property.

Pressing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are pressed, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key pressed, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is pressed.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'KeyPress''KeyPress''KeyPress''KeyPress'

The KeyPressFcn callback is not supported in the Live Editor.

For more information about specifying callback property values and using callback arguments, see Specify a Callback Function.

The CurrentCharacter property also returns character information.

Key-release callback, specified as one of these values

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user presses a key while the figure or a child object has focus. If the user releases a key on a UIControl or Table component, the callback does not execute unless the Enable property is set to 'off' or 'inactive'.

The KeyReleaseFcn callback can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of this object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that corresponds to the key or keys that are released.

Pressing certain keys or modifying keys with the Ctrl key might return unprintable characters in this property.

Pressing and releasing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are released, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key released, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is released.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'KeyRelease''KeyRelease''KeyRelease''KeyRelease'

The KeyReleaseFcn callback is not supported in the Live Editor.

For more information about specifying callback property values and using callback arguments, see Specify a Callback Function.

Window Callbacks

expand all

Close request callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Specify a Callback Function.

This callback executes whenever a user attempts to close a figure window. You can, for example, display a dialog box to ask a user to confirm or cancel the close operation or to prevent users from closing a figure that contains a UI.

The basic mechanism is:

  1. A user issues the close or close all command from the command line, closes the figure from the computer window manager menu, or closes the figure by quitting MATLAB.

  2. The close operation executes the function defined by the figure CloseRequestFcn property. The default value is 'closereq'. The 'closereq' operation unconditionally deletes the figure, destroying the window.

Unless the close request function calls the delete or close function, MATLAB never closes the figure. (You can call delete(f) from the command line if you have created a window with a nondestructive close request function.)

Example: Code CloseRequestFcn to Display Dialog Box

This example shows how to code the close request function to display a question dialog box asking the user to confirm the close operation. Save the code to a writable folder on your system.

function my_closereq(src,event)% Close request function % to display a question dialog box selection = questdlg('Close This Figure?', ... 'Close Request Function', ... 'Yes','No','Yes'); switch selection case 'Yes' delete(gcf) case 'No' return endend

Now, create a figure specifying my_closereq for the CloseRequestFcn. Notice that the function handle does not explicitly refer to any input arguments, but the function declaration includes two input arguments. MATLAB passes these arguments automatically when the callback executes. The first argument is the UI component that triggered the callback, and the second argument provides event data to the callback function.

figure('CloseRequestFcn',@my_closereq)

Close the figure window and the question dialog box displays.

Size changed callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

Define this callback to customize the app layout when the size of this container changes (e.g., when the user resizes the window).

The SizeChangedFcn callback executes when:

  • This container becomes visible for the first time.

  • This container is visible while its size changes.

  • This container becomes visible for the first time after its size changes. This situation occurs when the size changes while the container is invisible, and then it becomes visible later.

Other important points to consider when defining a SizeChangedFcn callback:

  • Consider delaying the display of this container until after all the variables that the SizeChangedFcn uses are defined. This practice can prevent the SizeChangedFcn callback from returning an error. To delay the display of the container, set its Visible property to 'off'. Then, set the Visible property to 'on' after you define the variables that your SizeChangedFcn callback uses.

  • If your app contains nested containers, they resize from the inside out.

  • To access the container that is resizing from within the SizeChangedFcn, refer to the source object (the first input argument in the callback) or use the gcbo function.

Tip

As an easy alternative to specifying a SizeChangedFcn callback, you can set the Units property of all the objects you put inside a container to 'normalized'. Doing so makes those components scale proportionally with the container.

Example: Edit Field With Constant Height

Use the SizeChangedFcn callback to constrain the size of UI components. For instance, the following code creates a UI that has an edit field at the top of the window. As the user resizes the window, the sbar function restricts its height to 20 pixels. The function also sets the edit field’s width to the width of the figure. Use dot notation to set and query properties.

function myuif = figure('Visible','off','SizeChangedFcn',@sbar); u = uicontrol('Style','edit','Tag','StatusBar');f.Visible = 'on'; function sbar(src,event) old_units = src.Units; src.Units = 'pixels'; sbar_units = u.Units; u.Units = 'pixels'; fpos = src.Position; upos = [1 fpos(4) - 20 fpos(3) 20]; u.Position = upos; u.Units = sbar_units; src.Units = old_units; u.Visible = 'on'; endend

Notice that the function handle for sbar does not explicitly refer to any input arguments, but the function declaration includes two input arguments. MATLAB passes these arguments automatically when the callback executes. The first argument is the UI component that triggered the callback, and the second argument provides event data to the callback function.

Window button down callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user clicks anywhere in the figure or one of its child objects. If the user clicks a UIControl or Table component, the callback does not execute unless the Enable property is set to 'off' or 'inactive'.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Specify a Callback Function.

Window button motion callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

Typically, this callback function executes whenever the user moves the pointer within the figure. However, if the user clicks and holds the mouse button and moves the pointer outside the figure, the WindowButtonMotionFcn callback executes while the pointer is outside the figure.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Specify a Callback Function.

Example: Simple Drawing App

This example shows how to create a drawing app that uses the WindowButtonMotionFcn callback. Copy and paste the following code into the editor and run it. Then use the mouse to draw a set of connected line segments:

  • Click and drag inside the axes to draw the first line segment.

  • Click again to define an anchor point for the line segment.

  • Move the mouse to add another line segment.

  • Right-click to end drawing mode.

function drawing_appfigure('WindowButtonDownFcn',@wbdcb)ah = axes('SortMethod','childorder');axis ([1 10 1 10])title('Click and drag') function wbdcb(src,event) seltype = src.SelectionType; if strcmp(seltype,'normal') src.Pointer = 'circle'; cp = ah.CurrentPoint; xinit = cp(1,1); yinit = cp(1,2); hl = line('XData',xinit,'YData',yinit,... 'Marker','p','color','b'); src.WindowButtonMotionFcn = @wbmcb; src.WindowButtonUpFcn = @wbucb; end function wbmcb(src,event) cp = ah.CurrentPoint; xdat = [xinit,cp(1,1)]; ydat = [yinit,cp(1,2)]; hl.XData = xdat; hl.YData = ydat; drawnow end function wbucb(src,event) last_seltype = src.SelectionType; if strcmp(last_seltype,'alt') src.Pointer = 'arrow'; src.WindowButtonMotionFcn = ''; src.WindowButtonUpFcn = ''; else return end end endend

Notice that the callback function handles do not explicitly refer to any input arguments, but the function declarations include two input arguments. MATLAB passes these arguments automatically when the callbacks execute. The first argument is the UI component that triggered the callback, and the second argument provides event data to the callback function.

Window button-up callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user releases the mouse button anywhere in the figure or one of its child objects. If the user releases the mouse button on a UIControl or Table component, the callback does not execute unless the Enable property is set to 'off' or 'inactive'.

The button-up actions are associated with button-down actions in the figure. The mouse pointer must be inside the figure when the button-down action occurs, but it can be outside the figure when the button-up action occurs.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Specify a Callback Function.

Window key-press callback, specified as one of these values

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user presses a key while the figure or a child object has focus.

This callback function can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of this object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that appears as a result of pressing the key or keys.

Pressing certain keys or modifying keys with the Ctrl key might return unprintable characters in this property.

Pressing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are pressed, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key pressed, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is pressed.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'WindowKeyPress''WindowKeyPress''WindowKeyPress''WindowKeyPress'

The WindowKeyPressFcn callback is not supported in the Live Editor.

For more information about specifying callback property values and using callback arguments, see Specify a Callback Function.

Window key-release callback, specified as one of these values

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user releases a key while the figure or a child object has focus.

This callback function can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of this object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that corresponds to the key or keys that are released.

Pressing certain keys or modifying keys with the Ctrl key might return unprintable characters in this property.

Pressing and releasing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are released, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key released, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is released.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'WindowKeyRelease''WindowKeyRelease''WindowKeyRelease''WindowKeyRelease'

The WindowKeyReleaseFcn callback is not supported in the Live Editor.

For more information about specifying callback property values and using callback arguments, see Specify a Callback Function.

Window scroll wheel callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user moves the scroll wheel while the figure or any if its children have focus. However, other objects can capture scroll wheel movement and interfere with the execution of this callback.

Executing this callback has no effect on the CurrentObject and SelectionType properties.

The WindowScrollWheelFcn callback can access specific information when the user rotates the scroll wheel. MATLAB passes this information in a ScrollWheelData object as the second argument to your callback function. This table lists the properties of the ScrollWheelData object.

Property

Contents

VerticalScrollCount

A positive or negative number that indicates the direction and number of scroll wheel clicks. Scrolling down returns a positive value. Scrolling up returns a negative value.

The vertical scroll count is the sum of all scroll wheel clicks that occurred since the last time the callback executed. Typically, the value is 1 or -1. However, the scroll count can have a larger magnitude if the WindowScrollWheelFcn callback takes a long time to return, or if the user spins the scroll wheel very fast.

VerticalScrollAmount

The number of lines scrolled for each click of the scroll wheel. Typically, the value is 3, but some systems might return a different value depending on how the mouse is configured.

Source

Object that executes the callback.

EventName'WindowScrollWheel'

The WindowScrollWheelFcn callback is not supported in the Live Editor.

For more information about specifying callback property values and using callback arguments, see Specify a Callback Function.

Example: App for Changing x-Axis Limits

This example shows how to create an app that displays a plot. The user can scroll to change the limits of the x-axis. Copy and paste the following code into the editor and run it.

function scroll_wheel% Shows how to use WindowScrollWheelFcn property% f = figure('WindowScrollWheelFcn',@figScroll,'Name','Scroll Wheel Demo'); x = [0:.1:40]; y = 4.*cos(x)./(x+2); a = axes; h = plot(x,y); title('Rotate the scroll wheel') function figScroll(src,event) if event.VerticalScrollCount > 0 xd = h.XData; inc = xd(end)/20; x = [0:.1:xd(end)+inc]; re_eval(x) elseif event.VerticalScrollCount < 0 xd = h.XData; inc = xd(end)/20; x = [0:.1:xd(end)-inc+.1]; % Don't let xd = 0; re_eval(x) end end function re_eval(x) y = 4.*cos(x)./(x+2); h.YData = y; h.XData = x; a.XLim = [0 x(end)]; drawnow endend

Notice that the function handle for figScroll does not explicitly refer to any input arguments, but the function declaration includes two input arguments. MATLAB passes these arguments automatically when the callback executes. The first argument is the UI component that triggered the callback, and the second argument provides event data to the callback function.

Callback Execution Control

expand all

Ability to become current object, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Sets the current object to the Figure when the user clicks the component in the running app. Both the CurrentObject property of the Figure and the gco function return the Figure as the current object.

  • 'off' — The current object does not update when the user clicks the figure in the running app.

Parent/Child

expand all

Figure parent, returned as a root object.

Children of the Figure, returned as an empty GraphicsPlaceholder or a 1-D array of objects.

You cannot add or remove children using the Children property. Use this property to view the list of children or to reorder the children. The order of the children reflects the front-to-back order (stacking order) of the components on the screen. MATLAB might not allow you to change the order of certain objects. For example, UIControl and Legend objects are always in front of Axes objects.

To add a child to this list, set the Parent property of the child component to the Figure object.

Objects with the HandleVisibility property set to 'off' are not listed in the Children property.

Visibility of figure object, specified as 'on', 'callback', or 'off'.

This property determines whether a figure is in its parent’s (the root’s) list of children. HandleVisibility is useful for preventing command-line users from accidentally drawing into, or deleting a figure that contains only user interface components (such as a dialog box).

If an object is not in its parent's list of children, functions that find objects by searching the object hierarchy or querying properties cannot return that object. Such functions include get, findobj, gca, gcf, gco, newplot, cla, clf, and close.

When the HandleVisibility property value is restricted using the 'callback' or 'off' settings, the object does not appear in the parent object Children property, figures do not appear in the root CurrentFigure property, objects do not appear in the root CallbackObject property or in the figure CurrentObject property, and axes do not appear in their parent CurrentAxes property.

Set the root ShowHiddenHandles property to 'on' to make all objects visible, regardless of their HandleVisibility settings (this does not affect the values of the HandleVisibility properties).

Identifiers

expand all

Number title, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

When you set this property to 'on', the title of the figure includes the phrase 'Figure n', where n is the value of the Number property.

Both the NumberTitle and IntegerHandle must be set to 'on' to show to show the number in the title.

Use integer handle, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

If you set the IntegerHandle property to 'on', MATLAB finds the lowest integer value that is not used by an existing figure and sets the Number property to that value. If you delete a figure, MATLAB can reuse its number on a new figure.

If you set the IntegerHandle property to 'off', MATLAB does not assign an integer value to the figure, and it sets the Number property to an empty array.

To show the figure number in the title bar, both IntegerHandle and NumberTitle must be set to 'on'.

File name for saving the figure, specified as a character vector or a string scalar. GUIDE uses this property to store the name of the UI layout file that it saves.

Example: figure('FileName','myfile.fig') sets the file name to myfile.fig.

This property is read-only.

Type of Figure object, returned as 'figure'. Use this property to find all objects of a given type within a plotting hierarchy.

Version History

Introduced before R2006a

expand all

The GraphicsSmoothing property will be removed in a future release. All graphics will be smooth when the property is removed.

The Renderer and RendererMode properties of figures will have no effect in a future release. It will no longer be necessary to change the renderer when these properties are disabled.

See Also

gcf | figure | groot

Topics

  • Access Property Values
  • Default Property Values

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Control appearance and behavior of figure window (18)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Control appearance and behavior of figure window (2024)

References

Top Articles
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 5744

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.