Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Axes Properties

Axes appearance and behavior

Axes properties control the appearance and behavior of an Axes object. By changing property values, you can modify certain aspects of the axes.

Starting in R2014b, you can use dot notation to query and set properties.

ax = gca;
c = ax.Color;
ax.Color = 'blue';

If you are using an earlier release, use the get and set functions instead.

Font

expand all

Font name, specified a supported font name or 'FixedWidth'. To display and print properly, you must choose a font that your system supports. The default font depends on the specific operating system and locale.

To use a fixed-width font that looks good in any locale, use 'FixedWidth'. The 'FixedWidth' value relies on the root FixedWidthFontName property. Setting the root FixedWidthFontName property causes an immediate update of the display to use the new font.

Example: 'Cambria'

Character thickness, specified as one of these values:

  • 'normal' — Default weight as defined by the particular font

  • 'bold' — Thicker character outlines than normal

MATLAB® uses the FontWeight property to select a font from those available on your system. Not all fonts have a bold font weight. Therefore, specifying a bold font weight still can result in the normal font weight.

Font size, specified as a scalar numeric value. The font size affects the title, axis labels, and tick labels. It also affects any legends or colorbars associated with the axes. The default font size depends on the specific operating system and locale. By default, the font size is measured in points. To change the units, set the FontUnits property.

MATLAB automatically scales some of the text to a percentage of the axes font size.

  • Titles and axis labels — 110% of the axes font size by default. To control the scaling, use the TitleFontSizeMultiplier and LabelFontSizeMultiplier properties.

  • Legends and colorbars — 90% of the axes font size by default. To specify a different font size, set the FontSize property for the Legend or Colorbar object instead.

Example: ax.FontSize = 12

Selection mode for the font size, specified as one of these values:

  • 'auto' — Font size specified by MATLAB. If you resize the axes to be smaller than the default size, the font size might scale down to improve readability and layout.

  • 'manual' — Font size specified manually. Do not scale the font size as the axes size changes. To specify the font size, set the FontSize property.

Character slant, specified as one of these values:

  • 'normal' — No character slant

  • 'italic' — Slanted characters

Not all fonts have both font styles. Therefore, the italic font might look the same as the normal font.

Scale factor for the label font size, specified as a numeric value greater than 0. The scale factor is applied to the value of the FontSize property to determine the font size for the x-axis, y-axis, and z-axis labels.

Example: ax.LabelFontSizeMultiplier = 1.5

Scale factor for the title font size, specified as a numeric value greater than 0. The scale factor is applied to the value of the FontSize property to determine the font size for the title.

Example: ax.TitleFontSizeMultiplier = 1.75

Title character thickness, specified as one of these values:

  • 'bold' — Thicker characters outlines than normal

  • 'normal' — Default weight as defined by the particular font

Example: ax.TitleFontWeight = 'normal'

Font size units, specified as one of these values.

UnitsDescription
'points'Points. One point equals 1/72 inch.
'inches'Inches.
'centimeters'Centimeters.
'normalized' Interpret font size as a fraction of the axes height. If you resize the axes, the font size modifies accordingly. For example, if the FontSize is 0.1 in normalized units, then the text is 1/10 of the height value stored in the axes Position property.
'pixels'

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.

To set both the font size and the font units in a single function call, you first must set the FontUnits property so that the Axes object correctly interprets the specified font size.

Character smoothing, specified as 'on' or 'off'.

ValueDescriptionResult
'on'

Use antialiasing to make text appear smoother on the screen.

Example: ax.FontSmoothing = 'on'

'off'

Do not use antialiasing. Use this setting if the text seems blurry.

Example: ax.FontSmoothing = 'off'

Ticks

expand all

Tick values, specified as a vector of increasing values. If you do not want tick marks along the axis, then specify an empty vector []. The tick values are the locations along the axis where the tick marks appear. The tick labels are the labels that you see next to each tick mark. Use the XTickLabels, YTickLabels, and ZTickLabels properties to specify the associated labels.

Example: ax.XTick = [2 4 6 8 10]

Example: ax.YTick = 0:10:100

Alternatively, use the xticks, yticks, and zticks functions to specify the tick values. For an example, see Specify Axis Tick Values and Labels.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Selection mode for the tick values, specified as one of these values:

  • 'auto' — Automatically select the tick values based on the range of data for the axis.

  • 'manual' — Manually specify the tick values. To specify the values, set the XTick, YTick, or ZTick property.

Example: ax.XTickMode = 'auto'

Tick labels, specified as a cell array of character vectors or a string array. If you do not want tick labels to show, then specify an empty cell array {}. If you do not specify enough labels for all the ticks values, then the labels repeat.

Tick labels support TeX and LaTeX markup. See the TickLabelInterpreter property for more information.

Example: ax.XTickLabel = {'Jan','Feb','Mar','Apr'}

Alternatively, use the xticklabels, yticklabels, and zticklabels functions. For an example, see Specify Axis Tick Values and Labels.

Selection mode for the tick labels, specified as one of these values:

  • 'auto' — Automatically select the tick labels.

  • 'manual' — Manually specify the tick labels. To specify the labels, set the XTickLabel, YTickLabel, or ZTickLabel property.

Example: ax.XTickLabelMode = 'auto'

Tick label interpretation, specified as one of these values:

  • 'tex' — Interpret labels using a subset of TeX markup.

  • 'latex' — Interpret labels using a subset of LaTeX markup.

  • 'none' — Display literal characters.

TeX Markup

By default, MATLAB supports a subset of TeX markup. Use TeX markup to add superscripts and subscripts, modify the text type and color, and include special characters in the text.

The table that follows lists the supported modifiers when the TickLabelInterpreter property is set to 'tex', which is the default value. Modifiers remain in effect until the end of the text, except for superscripts and subscripts which only modify the next character or the text within the curly braces {}.

ModifierDescriptionExample
^{ }Superscript'text^{superscript}'
_{ }Subscript'text_{subscript}'
\bfBold font'\bf text'
\itItalic font'\it text'
\slOblique font (rarely available)'\sl text'
\rmNormal font'\rm text'
\fontname{specifier}Set specifier as the name of a font family to change the font style. You can use this with other modifiers.'\fontname{Courier} text'
\fontsize{specifier}Set specifier as a scalar numeric value to change the font size.'\fontsize{15} text'
\color{specifier}Set specifer as one of these colors: red, green, yellow, magenta, blue, black, white, gray, darkGreen, orange, or lightBlue.'\color{magenta} text'
\color[rgb]{specifier}Set specifier as a three-element RGB triplet to change the font color.'\color[rgb]{0,0.5,0.5} text'

This table lists the supported special characters with the Interpreter property set to 'tex'.

Character SequenceSymbolCharacter SequenceSymbolCharacter SequenceSymbol

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ϵ

\Delta

Δ

\spadesuit

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

\copyright

©

LaTeX Markup

To use LaTeX markup, set the TickLabelInterpreter property to 'latex'. Use dollar symbols around the text, for example, use '$\int_1^{20} x^2 dx$' for inline mode or '$$\int_1^{20} x^2 dx$$' for display mode.

The displayed text uses the default LaTeX font style. To change the font style, use LaTeX markup within the text. The FontName, FontWeight, and FontAngle properties have no effect.

The maximum size of the text that you can use with the LaTeX interpreter is 1200 characters. For multiline text, this limit reduces by about 10 characters per line. For more information about the LaTeX system, see The LaTeX Project website at www.latex-project.org.

Tick label rotation, specified as a numeric value in degrees. Positive values give counterclockwise rotation. Negative values give clockwise rotation.

Example: ax.XTickLabelRotation = 45

Example: ax.YTickLabelRotation = 90

Alternatively, use the xtickangle, ytickangle, and ztickangle functions.

Minor tick marks, specified as one of these values:

  • 'off' — Do not display minor tick marks. This value is the default for an axis with a linear scale.

  • 'on' — Display minor tick marks between the major tick marks on the axis. The space between the major tick marks determines the number of minor tick marks. This value is the default for an axis with a log scale.

Example: ax.XMinorTick = 'on'

Tick mark direction, specified as one of these values:

  • 'in' — Direct the tick marks inward from the axis lines. (Default for 2-D views)

  • 'out' — Direct the tick marks outward from the axis lines. (Default for 3-D views)

  • 'both' — Center the tick marks over the axis lines.

Example: ax.TickDir = 'out'

Selection mode for the TickDir property, specified as one of these values:

  • 'auto' — Automatically select the tick direction based on the current view.

  • 'manual' — Manually specify the tick direction. To specify the tick direction, set the TickDir property.

Example: ax.TickDirMode = 'auto'

Tick mark length, specified as a two-element vector of the form [2Dlength 3Dlength]. The first element is the tick mark length in 2-D views and the second element is the tick mark length in 3-D views. Specify the values in units normalized relative to the longest of the visible x-axis, y-axis, or z-axis lines.

Example: ax.TickLength = [0.02 0.035]

Rulers

expand all

Minimum and maximum limits, specified as a two-element vector of the form [min max], where max is greater than min. You can specify the limits as numeric, categorical, datetime, or duration values. However, the type of values that you specify must match the type of values along the axis.

You can specify both limits or you can specify one limit and let the axes automatically calculate the other. For an automatically calculated minimum or maximum limit, use -inf or inf, respectively.

Example: ax.XLim = [0 10]

Example: ax.YLim = [-inf 10]

Example: ax.ZLim = [0 inf]

Alternatively, use the xlim, ylim, and zlim functions to set the limits. For an example, see Specify Axis Limits.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | datetime | duration

Selection mode for the axis limits, specified as one of these values:

  • 'auto' — Automatically select the axis limits based on the data plotted, which is, the total span of the XData, YData, or ZData of all the objects displayed in the axes.

  • 'manual' — Manually specify the axis limits. To specify the axis limits, set the XLim, YLim, or ZLim property.

Example: ax.XLimMode = 'auto'

Axis ruler, returned as a ruler object. The ruler controls the appearance and behavior of the x-axis, y-axis, or z-axis. Modify the appearance and behavior of a particular axis by accessing the associated ruler and setting ruler properties. The type of ruler that MATLAB creates for each axis depends on the plotted data. For a list of ruler properties, see:

For example, access the ruler for the x-axis through the XAxis property. Then, change the Color property of the ruler, and thus the color of the x-axis, to red. Similarly, change the color of the y-axis to green.

ax = gca;
ax.XAxis.Color = 'r';
ax.YAxis.Color = 'g';
If the Axes object has two y-axes, then the YAxis property stores two ruler objects.

x-axis location, specified as one of the values in this table. This property applies only to 2-D views.

ValueDescriptionResult
'bottom'

Bottom of the axes.

Example: ax.XAxisLocation = 'bottom'

'top'

Top of the axes.

Example: ax.XAxisLocation = 'top'

'origin'

Through the origin point (0,0).

Example: ax.XAxisLocation = 'origin'

y-axis location, specified as one of the values in this table. This property applies only to 2-D views.

ValueDescriptionResult
'left'

Left side of the axes.

Example: ax.YAxisLocation = 'left'

'right'

Right side of the axes.

Example: ax.YAxisLocation = 'right'

'origin'

Through the origin point (0,0).

Example: ax.YAxisLocation = 'origin'

Color of the axis line, tick values, and labels in the x, y, or z direction, specified as an RGB triplet or one of the color options listed in the next table. The color also affects the grid lines, unless you specify the grid line color using the GridColor or MinorGridColor property.

For a custom color, specify an RGB triplet. 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]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

OptionDescriptionEquivalent RGB Triplet
'red' or 'r'Red[1 0 0]
'green' or 'g'Green[0 1 0]
'blue' or 'b'Blue[0 0 1]
'yellow' or 'y'Yellow[1 1 0]
'magenta' or 'm'Magenta[1 0 1]
'cyan' or 'c'Cyan[0 1 1]
'white' or 'w'White[1 1 1]
'black' or 'k'Black[0 0 0]
'none'No colorNot applicable

Example: ax.XColor = [1 1 0]

Example: ax.YColor = 'y'

Example: ax.ZColor = 'yellow'

Property for setting the x-axis grid color, specified as 'auto' or 'manual'. The mode value only affects the x-axis grid color. The x-axis line, tick values, and labels always use the XColor value, regardless of the mode.

The x-axis grid color depends on both the XColorMode property and the GridColorMode property, as shown here.

XColorModeGridColorModex-Axis Grid Color
'auto''auto'GridColor property
'manual'GridColor property
'manual''auto'XColor property
'manual'GridColor property

The x-axis minor grid color depends on both the XColorMode property and the MinorGridColorMode property, as shown here.

XColorModeMinorGridColorModex-Axis Minor Grid Color
'auto''auto'MinorGridColor property
'manual'MinorGridColor property
'manual''auto'XColor property
'manual'MinorGridColor property

Property for setting the y-axis grid color, specified as 'auto' or 'manual'. The mode value only affects the y-axis grid color. The y-axis line, tick values, and labels always use the YColor value, regardless of the mode.

The x-axis grid color depends on both the YColorMode property and the GridColorMode property, as shown here.

YColorModeGridColorModey-Axis Grid Color
'auto''auto'GridColor property
'manual'GridColor property
'manual''auto'YColor property
'manual'GridColor property

The y-axis minor grid color depends on both the YColorMode property and the MinorGridColorMode property, as shown here.

YColorModeMinorGridColorModey-Axis Minor Grid Color
'auto''auto'MinorGridColor property
'manual'MinorGridColor property
'manual''auto'YColor property
'manual'MinorGridColor property

Property for setting the z-axis grid color, specified as 'auto' or 'manual'. The mode value only affects the z-axis grid color. The z-axis line, tick values, and labels always use the ZColor value, regardless of the mode.

The z-axis grid color depends on both the ZColorMode property and the GridColorMode property, as shown here.

ZColorModeGridColorModez-Axis Grid Color
'auto''auto'GridColor property
'manual'GridColor property
'manual''auto'ZColor property
'manual'GridColor property

The z-axis minor grid color depends on both the ZColorMode property and the MinorGridColorMode property, as shown here.

ZColorModeMinorGridColorModez-Axis Minor Grid Color
'auto''auto'MinorGridColor property
'manual'MinorGridColor property
'manual''auto'ZColor property
'manual'MinorGridColor property

x-axis direction, specified as one of these values.

ValueDescriptionResult in 2-DResult in 3-D
'normal'

Values increase from left to right.

Example: ax.XDir = 'normal'

'reverse'

Values increase from right to left.

Example: ax.XDir = 'reverse'

y-axis direction, specified as one of these values.

ValueDescriptionResult in 2-DResult in 3-D
'normal'

Values increase from bottom to top (2-D view) or front to back (3-D view).

Example: ax.YDir = 'normal'

'reverse'

Values increase from top to bottom (2-D view) or back to front (3-D view).

Example: ax.YDir = 'reverse'

z-axis direction, specified as one of these values.

ValueDescriptionResult in 3-D
'normal'

Values increase pointing out of the screen (2-D view) or from bottom to top (3-D view).

Example: ax.ZDir = 'normal'

'reverse'

Values increase pointing into the screen (2-D view) or from top to bottom (3-D view).

Example: ax.ZDir = 'reverse'

Axis scale, specified as one of these values.

ValueDescriptionResult
'linear'

Linear scale

Example: ax.XScale = 'linear'

'log'

Log scale

Example: ax.XScale = 'log'

Grids

expand all

Grid lines, specified as one of these values:

  • 'off' — Do not display the grid lines.

  • 'on' — Display grid lines perpendicular to the axis; for example, along lines of constant x, y, or z values.

Alternatively, use the grid on or grid off command to set all three properties to 'on' or 'off', respectively. For more information, see grid.

Example: ax.XGrid = 'on'

Placement of grid lines and tick marks in relation to graphic objects, specified as one of these values:

  • 'bottom' — Display tick marks and grid lines under graphics objects.

  • 'top' — Display tick marks and grid lines over graphics objects.

This property affects only 2-D views.

Example: ax.Layer = 'top'

Line style for grid lines, specified as one of the line styles in this table.

Line StyleDescriptionResulting Line
'-'Solid line

'--'Dashed line

':'Dotted line

'-.'Dash-dotted line

'none'No lineNo line

To display the grid lines, use the grid on command or set the XGrid, YGrid, or ZGrid property to 'on'.

Example: ax.GridLineStyle = '--'

Color of grid lines, specified as an RGB triplet or one of the color options listed in the table.

For a custom color, specify an RGB triplet. 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]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

OptionDescriptionEquivalent RGB Triplet
'red' or 'r'Red[1 0 0]
'green' or 'g'Green[0 1 0]
'blue' or 'b'Blue[0 0 1]
'yellow' or 'y'Yellow[1 1 0]
'magenta' or 'm'Magenta[1 0 1]
'cyan' or 'c'Cyan[0 1 1]
'white' or 'w'White[1 1 1]
'black' or 'k'Black[0 0 0]
'none'No colorNot applicable

To set the colors for the axes box outline, use the XColor, YColor, and ZColor properties.

To display the grid lines, use the grid on command or set the XGrid, YGrid, or ZGrid property to 'on'.

Example: ax.GridColor = [0 0 1]

Example: ax.GridColor = 'b'

Example: ax.GridColor = 'blue'

Property for setting the grid color, specified as one of these values:

  • 'auto' — Check the values of the XColorMode, YColorMode, and ZColorMode properties to determine the grid line colors for the x, y, and z directions.

  • 'manual' — Use GridColor to set the grid line color for all directions.

Grid-line transparency, specified as a value in the range [0,1]. A value of 1 means opaque and a value of 0 means completely transparent.

Example: ax.GridAlpha = 0.5

Selection mode for the GridAlpha property, specified as one of these values:

  • 'auto' — Default transparency value of 0.15.

  • 'manual' — Manually specify the transparency value. To specify the value, set the GridAlpha property.

Example: ax.GridAlphaMode = 'auto'

Minor grid lines, specified as one of these values:

  • 'off' — Do not display grid lines.

  • 'on' — Display grid lines aligned with the minor tick marks of the axis. You do not need to enable minor ticks to display minor grid lines.

Alternatively, use the grid minor command to toggle the visibility of the minor grid lines.

Example: ax.XMinorGrid = 'on'

Line style for minor grid lines, specified as one of the line styles shown in this table.

Line StyleDescriptionResulting Line
'-'Solid line

'--'Dashed line

':'Dotted line

'-.'Dash-dotted line

'none'No lineNo line

To display minor grid lines, use the grid minor command or set the XGridMinor, YGridMinor, or ZGridMinor property to 'on'.

Example: ax.MinorGridLineStyle = '-.'

Color of minor grid lines, specified as an RGB triplet or one of the color options listed in the table.

For a custom color, specify an RGB triplet. 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]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

OptionDescriptionEquivalent RGB Triplet
'red' or 'r'Red[1 0 0]
'green' or 'g'Green[0 1 0]
'blue' or 'b'Blue[0 0 1]
'yellow' or 'y'Yellow[1 1 0]
'magenta' or 'm'Magenta[1 0 1]
'cyan' or 'c'Cyan[0 1 1]
'white' or 'w'White[1 1 1]
'black' or 'k'Black[0 0 0]
'none'No colorNot applicable

To display minor grid lines, use the grid minor command or set the XGridMinor, YGridMinor, or ZGridMinor property to 'on'.

Example: ax.MinorGridColor = [0 0 1]

Example: ax.MinorGridColor = 'b'

Example: ax.MinorGridColor = 'blue'

Property for setting the minor grid color, specified as one of these values:

  • 'auto' — Check the values of the XColorMode, YColorMode, and ZColorMode properties to determine the grid line colors for the x, y, and z directions.

  • 'manual' — Use MinorGridColor to set the grid line color for all directions.

Minor grid line transparency, specified as a value in the range [0,1]. A value of 1 means opaque and a value of 0 means completely transparent.

Example: ax.MinorGridAlpha = 0.5

Selection mode for the MinorGridAlpha property, specified as one of these values:

  • 'auto' — Default transparency value of 0.25.

  • 'manual' — Manually specify the transparency value. To specify the value, set the MinorGridAlpha property.

Example: ax.MinorGridAlphaMode = 'auto'

Labels

expand all

Text object for axes title. To add a title, set the String property of the text object. To change the title appearance, such as the font style or color, set other properties. For a complete list, see Text Properties.

ax = gca;
ax.Title.String = 'My Title';
ax.Title.FontWeight = 'normal';

Alternatively, use the title function to add a title and control the appearance.

title('My Title','FontWeight','normal')

Note

This text object is not contained in the axes Children property, cannot be returned by findobj, and does not use default values defined for text objects.

Text object for axis label. To add an axis label, set the String property of the text object. To change the label appearance, such as the font size, set other properties. For a complete list, see Text Properties.

ax = gca;
ax.YLabel.String = 'My y-Axis Label';
ax.YLabel.FontSize = 12;

Alternatively, use the xlabel, ylabel, and zlabel functions to add an axis label and control the appearance.

ylabel('My y-Axis Label','FontSize',12)

Note

These text objects are not contained in the axes Children property, cannot be returned by findobj, and do not use default values defined for text objects.

This property is read-only.

Legend associated with the Axes object, specified as a Legend object. To add a legend to the axes, use the legend function. Then, you can use this property to modify the legend. For a complete list of properties, see Legend Properties.

plot(rand(3))
legend({'Line 1','Line 2','Line 3'},'FontSize',12)
ax = gca;
ax.Legend.TextColor = 'red';

You also can use this property to determine if the axes has a legend.

ax = gca;
lgd = ax.Legend
if ~isempty(lgd)
    disp('Legend Exists')
end

Multiple Plots

expand all

Color order, specified as a three-column matrix of RGB triplets. Each row of the matrix defines one color in the color order. The default color order has seven colors.

Default Color OrderAssociated RGB Triplets

    [    0    0.4470    0.7410
    0.8500    0.3250    0.0980
    0.9290    0.6940    0.1250
    0.4940    0.1840    0.5560
    0.4660    0.6740    0.1880
    0.3010    0.7450    0.9330
    0.6350    0.0780    0.1840]

Change Color Order Before Plotting

You must change the color order before plotting. Changing the order has no effect on existing plots. However, many graphics functions reset the color order back to the default value before plotting. To ensure that the axes uses your specified color order, use one of these approaches:

  • Change the default color order for the axes before plotting.

  • Set the NextPlot property of the axes to 'replacechildren'or 'add' before plotting.

For example, this code changes the default color order for all future axes.

co = [1    0  0.4
    0.8  0.2  0.5
    0.6  0.4  0.6
    0.4  0.6  0.7
    0.2  0.8  0.8
      0    1  0.9];
set(groot,'defaultAxesColorOrder',co)
plot(rand(5))
To revert to the original color order, use this command.
set(groot,'defaultAxesColorOrder','remove')

Alternatively, set the NextPlot property of the Axes object to 'replacechildren' before plotting. New plots replace existing plots and use the first color in the color order, but they do not reset other axes properties.

co = [1    0  0.4
    0.8  0.2  0.5
    0.6  0.4  0.6
    0.4  0.6  0.7
    0.2  0.8  0.8
      0    1  0.9];
ax = axes('ColorOrder',co,'NextPlot','replacechildren');
plot(ax,rand(5))

Next color to use in the color order, specified as a positive integer. For example, if this property is set to 1, then the next plot added to the axes uses the first color in the color order. If the index value exceeds the number of colors in the color order, then the index value modulo of the number of colors determines the next color used.

If you used a hold on command or if the NextPlot property of the axes is set to 'add', then the color order index value increases every time a new plot is added. Reset the color order by setting the ColorOrderIndex property to 1.

Example: ax.ColorOrderIndex = 5

Line-style order, specified as a character vector, a cell array of character vectors, or a string array. Create each element using one or more of the line-style specifiers listed in the table. You can combine a line and a marker specifier in a single element, such as '-*'.

Example: {'-*',':','o'}

MATLAB cycles through the line styles only after using all the colors contained in the ColorOrder property. The default LineStyleOrder has only one line style, '-'.

SpecifierLine Style
'-' (default) Solid line
'--'Dashed line
':'Dotted line
'-.'Dash-dotted line
'+'Plus sign markers
'o'Circle markers
'*'Star markers
'.'Point markers
'x'Cross markers
's'Square markers
'd'Diamond markers
'^'Upward-pointing triangle markers
'v'Downward-pointing triangle markers
'>'Right-pointing triangle markers
'<'Left-pointing triangle markers
'p'Five-pointed star (pentagram) markers
'h'Six-pointed star (hexagram) markers

Change Line-Style Order Before Plotting

You must change the line-style order before plotting. Changing the order has no effect on existing plots. However, many graphics functions reset the line-style order back to the default value before plotting. To ensure that the axes uses your specified line-style order, use one of these approaches:

  • Change the default line-style order for the axes before plotting.

  • Set the NextPlot property of the axes to 'replacechildren'or 'add' before plotting.

For example, this code changes the default line-style order for all future axes.

set(groot,'defaultAxesLineStyleOrder',{'-*',':','o'})
plot(rand(15))
To revert to the original line-style order, use this command.
set(groot,'defaultAxesLineStyleOrder','remove')

Alternatively, set the NextPlot property of the Axes object to 'replacechildren' before plotting. New plots replace existing plots and use the first color and line style, but they do not reset other axes properties.

ax = axes('LineStyleOrder',{'-*',':','o'},'NextPlot','replacechildren');
plot(ax,rand(15))

Next line style to use in the line-style order, specified as a positive integer. For example, if this property is set to 1, then the next plot added to the axes uses the first line style in the line-style order. If the index value exceeds the number of line styles in the line-style order, then the index value modulo of the number of line styles determines the next line style used.

If you used a hold on command or if the NextPlot property of the axes is set to 'add', then the index value increases every time you add a new plot. Subsequent plots cycle through the line-style order. Reset the line-style order by setting the LineStyleOrderIndex property to 1.

Example: ax.LineStyleOrderIndex = 1

Properties to reset when adding a new plot to the axes, specified as one of these values:

  • 'add' — Add new plots to the existing axes. Do not delete existing plots or reset axes properties before displaying the new plot.

  • 'replacechildren' — Delete existing plots before displaying the new plot. Reset the ColorOrderIndex and LineStyleOrderIndex properties to 1, but do not reset other axes properties. The next plot added to the axes uses the first color and line style based on the ColorOrder and LineStyle order properties. This value is similar to using cla before every new plot.

  • 'replace' — Delete existing plots and reset axes properties, except Position and Units, to their default values before displaying the new plot.

  • 'replaceall' — Delete existing plots and reset axes properties, except Position and Units, to their default values before displaying the new plot. This value is similar to using cla reset before every new plot.

Note

For Axes objects with only one y-axis, the 'replace' and 'replaceall' property values are equivalent. For Axes objects with two y-axes, the 'replace' value affects only the active side while the 'replaceall' value affects both sides.

Figures also have a NextPlot property. Alternatively, you can use the newplot function to prepare figures and axes for subsequent graphics commands.

Order for rendering objects, specified as one of these values:

  • 'depth' — Draw objects in back-to-front order based on the current view. Use this value to ensure that objects in front of other objects are drawn correctly.

  • 'childorder' — Draw objects in the order in which they are created by graphics functions, without considering the relationship of the objects in three dimensions. This value can result in faster rendering, particularly if the figure is very large, but also can result in improper depth sorting of the objects displayed.

Color and Transparency Maps

expand all

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

Example: ax.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.

Alternatively, use the colormap function to change the color map.

Scale for color mapping, specified as one of these values:

  • 'linear' — Linear scale. The tick values along the colorbar also use a linear scale.

  • 'log' — Log scale. The tick values along the colorbar also use a log scale.

Example: ax.ColorScale = 'log'

Color limits for objects in axes that use the colormap, specified as a two-element vector of the form [cmin cmax]. This property determines how data values map to the colors in the colormap where:

  • cmin specifies the data value that maps to the first color in the colormap.

  • cmax specifies the data value that maps to the last color in the colormap.

The Axes object interpolates data values between cmin and cmax across the colormap. Values outside this range use either the first or last color, whichever is closest.

Selection mode for the CLim property, specified as one of these values:

  • 'auto' — Automatically select the limits based on the color data of the graphics objects contained in the axes.

  • 'manual' — Manually specify the values. To specify the values, set the CLim property. The values do not change when the limits of the axes children change.

Transparency map, 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.

Scale for transparency mapping, specified as one of these values:

  • 'linear' — Linear scale

  • 'log' — Log scale

Example: ax.AlphaScale = 'log'

Alpha limits, specified as a two-element vector of the form [amin amax]. This property affects the AlphaData values of graphics objects, such as surface, image, and patch objects. This property determines how the AlphaData values map to the figure alpha map, where:

  • amin specifies the data value that maps to the first alpha value in the figure alpha map.

  • amax specifies the data value that maps to the last alpha value in the figure alpha map.

The Axes object interpolates data values between amin and amax across the figure alpha map. Values outside this range use either the first or last alpha map value, whichever is closest.

The Alphamap property of the figure contains the alpha map. For more information, see the alpha function.

Selection mode for the ALim property, specified as one of these values:

  • 'auto' — Automatically select the limits based on the AlphaData values of the graphics objects contained in the axes.

  • 'manual' — Manually specify the alpha limits. To specify the alpha limits, set the ALim property.

Box Styling

expand all

Background color, specified as an RGB triplet or one of the color options listed in the table.

For a custom color, specify an RGB triplet. 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]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

OptionDescriptionEquivalent RGB Triplet
'red' or 'r'Red[1 0 0]
'green' or 'g'Green[0 1 0]
'blue' or 'b'Blue[0 0 1]
'yellow' or 'y'Yellow[1 1 0]
'magenta' or 'm'Magenta[1 0 1]
'cyan' or 'c'Cyan[0 1 1]
'white' or 'w'White[1 1 1]
'black' or 'k'Black[0 0 0]
'none'No colorNot applicable

Example: ax.Color = [0 0 1];

Example: ax.Color = 'b';

Example: ax.Color = 'blue';

Line width of axes outline, tick marks, and grid lines, specified as a positive numeric value in point units. One point equals 1/72 inch.

Example: ax.LineWidth = 1.5

Box outline, specified as 'off' or 'on'.

ValueDescription2-D Result3-D Result
'off'

Do not display the box outline around the axes.

Example: ax.Box = 'off'

'on'

Display the box outline around the axes. For 3-D views, use the BoxStyle property to change extent of the outline.

Example: ax.Box = 'on'

The XColor, YColor, and ZColor properties control the color of the outline.

Example: ax.Box = 'on'

Box outline style, specified as 'back' or 'full'. This property affects only 3-D views.

ValueDescriptionResult
'back'

Outline the back planes of the 3-D box.

Example: ax.BoxStyle = 'back'

'full'

Outline the entire 3-D box.

Example: ax.BoxStyle = 'full'

Clipping of objects to the axes limits, specified as either 'on' or 'off'. The clipping behavior of an object within the Axes object depends on both the Clipping property of the Axes object and the Clipping property of the individual object. The property value of the Axes object has these effects:

  • 'on' — Enable each individual object within the axes to control its own clipping behavior based on the Clipping property value for the object.

  • 'off' — Disable clipping for all objects within the axes, regardless of the Clipping property value for the individual objects. Parts of objects can appear outside of the axes limits. For example, parts can appear outside the limits if you create a plot, use the hold on command, freeze the axis scaling, and then add a plot that is larger than the original plot.

This table lists the results for different combinations of Clipping property values.

Clipping Property for Axes ObjectClipping Property for Individual ObjectResult
'on''on'Individual object is clipped. Others might or might not be.
'on''off'Individual object is not clipped. Others might or might not be.
'off''on'All objects are unclipped.
'off''off'All objects are unclipped.

Clipping boundaries, specified as one of the values in this table. If a plot contains markers, then as long as the data point lies within the axes limits, MATLAB draws the entire marker.

The ClippingStyle property has no effect if the Clipping property is set to 'off'.

ValueDescriptionsIllustration of Boundary Region
'3dbox'

Clip plotted objects to the six sides of the axes box defined by the axis limits.

Thick lines might display outside the axes limits.

'rectangle'

Clip plotted objects to a rectangular boundary enclosing the axes in any given view.

Clip thick lines at the axes limits.

Background light color, specified as an RGB triplet or one of the color options listed in the table. The background light is a directionless light that shines uniformly on all objects in the axes. To add light, use the light function.

For a custom color, specify an RGB triplet. 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]. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.

OptionDescriptionEquivalent RGB Triplet
'red' or 'r'Red[1 0 0]
'green' or 'g'Green[0 1 0]
'blue' or 'b'Blue[0 0 1]
'yellow' or 'y'Yellow[1 1 0]
'magenta' or 'm'Magenta[1 0 1]
'cyan' or 'c'Cyan[0 1 1]
'white' or 'w'White[1 1 1]
'black' or 'k'Black[0 0 0]
'none'No color[0 0 0]

Example: ax.AmbientLightColor = [1 0 1]

Example: ax.AmbientLightColor = 'm'

Example: ax.AmbientLightColor = 'magenta'

Position

expand all

Size and location, including the labels and a margin, specified as a four-element vector of the form [left bottom width height]. By default, MATLAB measures the values in units normalized to the container. To change the units, set the Units property. The default value of [0 0 1 1] includes the whole interior of the container.

  • The left and bottom elements define the distance from the lower left corner of the container (typically a figure, panel, or tab) to the lower left corner of the outer position boundary.

  • The width and height elements are the outer position boundary dimensions.

These figures show the areas defined by the OuterPosition values (blue) and the Position values (red).

2-D View of Axes3-D View of Axes

For more information on the axes position, see Control Axes Layout.

Size and location, excluding a margin for the labels, specified as a four-element vector of the form [left bottom width height]. By default, MATLAB measures the values in units normalized to the container. To change the units, set the Units property.

  • The left and bottom elements define the distance from the lower left corner of the container (typically a figure, panel, or tab) to the lower left corner of the position boundary.

  • The width and height elements are the position boundary dimensions. For axes in a 3-D view, the Position property is the smallest rectangle that encloses the axes.

If you want to specify the position and account for the text around the axes, then set the OuterPosition property instead. These figures show the areas defined by the OuterPosition values (blue) and the Position values (red).

2-D View of Axes3-D View of Axes

For more information on the axes position, see Control Axes Layout.

This property is read-only.

Margins for the text labels, specified as a four-element vector of the form [left bottom right top]. By default, MATLAB measuers the values in units normalized to the container. To change the units, set the Units property.

The elements define the distances between the bounds of the Position property and the extent of the surrounding text. The Position values combined with the TightInset values define the tightest bounding box that encloses the axes and the surrounding text.

These figures show the areas defined by the OuterPosition values (blue), the Position values (red), and the Position expanded by the TightInset values (magenta).

2-D View of Axes3-D View of Axes

For more information, see Control Axes Layout.

Active position property during resize operation, specified as one of these values:

  • 'outerposition' — Hold the OuterPosition property constant.

  • 'position' — Hold the Position property constant.

A figure can change size if you interactively resize it or during a printing or exporting operation.

Position units, specified as one of these values.

UnitsDescription
'normalized' (default)Normalized with respect to the container, which is typically the figure or a panel. The lower left corner of the container maps to (0,0) and the upper right corner maps to (1,1).
'inches'Inches.
'centimeters'Centimeters.
'characters'

Based on the default uicontrol font of the graphics root object:

  • Character width = width of letter x.

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

'points'Typography points. One point equals 1/72 inch.
'pixels'

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.

When specifying the units as a Name,Value pair during object creation, you must set the Units property before specifying the properties that you want to use these units, such as Position.

Relative length of data units along each axis, specified as a three-element vector of the form [dx dy dz]. This vector defines the relative x, y, and z data scale factors. For example, specifying this property as [1 2 1] sets the length of one unit of data in the x-direction to be the same length as two units of data in the y-direction and one unit of data in the z-direction.

Alternatively, use the daspect function to change the data aspect ratio.

Example: ax.DataAspectRatio = [1 1 1]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Data aspect ratio mode, specified as one of these values:

  • 'auto' — Automatically select values that make best use of the available space. If PlotBoxAspectRatioMode and CameraViewAngleMode are also set to 'auto', then enable "stretch-to-fill" behavior. Stretch the axes so that it fills the available space as defined by the Position property.

  • 'manual' — Disable the "stretch-to-fill" behavior and use the manually specified data aspect ratio. To specify the values, set the DataAspectRatio property.

Relative length of each axis, specified as a three-element vector of the form [px py pz] defining the relative x-axis, y-axis, and z-axis scale factors. The plot box is a box enclosing the axes data region as defined by the axis limits.

Alternatively, use the pbaspect function to change the data aspect ratio.

If you specify the axis limits, data aspect ratio, and plot box aspect ratio, then MATLAB ignores the plot box aspect ratio. It adheres to the axis limits and data aspect ratio.

Example: ax.PlotBoxAspectRatio = [1 0.75 0.75]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Selection mode for the PlotBoxAspectRatio property, specified as one of these values:

  • 'auto' — Automatically select values that make best use of the available space. If DataAspectRatioMode and CameraViewAngleMode also are set to 'auto', then enable "stretch-to-fill" behavior. Stretch the Axes object so that it fills the available space as defined by the Position property.

  • 'manual' — Disable the "stretch-to-fill" behavior and use the manually specified plot box aspect ratio. To specify the values, set the PlotBoxAspectRatio property.

View

expand all

Azimuth and elevation of view, specified as a two-element vector of the form [azimuth elevation] defined in degree units. Alternatively, use the view function to set the view.

Example: ax.View = [45 45]

Type of projection onto a 2-D screen, specified as one of these values:

  • 'orthographic' — Maintain the correct relative dimensions of graphics objects regarding the distance of a given point from the viewer, and draw lines that are parallel in the data parallel on the screen.

  • 'perspective' — Incorporate foreshortening, which enables you to perceive depth in 2-D representations of 3-D objects. Perspective projection does not preserve the relative dimensions of objects. Instead, it displays a distant line segment smaller than a nearer line segment of the same length. Lines that are parallel in the data might not appear parallel on screen.

Camera location, or the viewpoint, specified as a three-element vector of the form [x y z]. This vector defines the axes coordinates of the camera location, which is the point from which you view the axes. The camera is oriented along the view axis, which is a straight line that connects the camera position and the camera target. For an illustration, see Camera Graphics Terminology.

If the Projection property is set to 'perspective', then as you change the CameraPosition setting, the amount of perspective also changes.

Alternatively, use the campos function to set the camera location.

Example: ax.CameraPosition = [0.5 0.5 9]

Data Types: single | double

Selection mode for the CameraPosition property, specified as one of these values:

  • 'auto' — Automatically set CameraPosition along the view axis. Calculate the position so that the camera lies a fixed distance from the target along the azimuth and elevation specified by the current view, as returned by the view function. Functions like rotate3d, zoom, and pan, change this mode to 'auto' to perform their actions.

  • 'manual' — Manually specify the value. To specify the value, set the CameraPosition property.

Camera target point, specified as a three-element vector of the form [x y z]. This vector defines the axes coordinates of the point. The camera is oriented along the view axis, which is a straight line that connects the camera position and the camera target. For an illustration, see Camera Graphics Terminology.

Alternatively, use the camtarget function to set the camera target.

Example: ax.CameraTarget = [0.5 0.5 0.5]

Data Types: single | double

Selection mode for the CameraTarget property, specified as one of these values:

  • 'auto' — Position the camera target at the centroid of the axes plot box.

  • 'manual' — Use the manually specified camera target value. To specify a value, set the CameraTarget property.

Vector defining upwards direction, specified as a three-element direction vector of the form [x y z]. For 2-D views, the default value is [0 1 0]. For 3-D views, the default value is [0 0 1]. For an illustration, see Camera Graphics Terminology.

Alternatively, use the camup function to set the upwards direction.

Example: ax.CameraUpVector = [sin(45) cos(45) 1]

Selection mode for the CameraUpVector property, specified as one of these values:

  • 'auto' — Automatically set the value to [0 0 1] for 3-D views so that the positive z-direction is up. Set the value to [0 1 0] for 2-D views so that the positive y-direction is up.

  • 'manual' — Manually specify the vector defining the upwards direction. To specify a value, set the CameraUpVector property.

Field of view, specified as a scalar angle greater than 0 and less than or equal to 180. Changing the camera view angle affects the size of graphics objects displayed in the axes, but does not affect the degree of perspective distortion. The greater the angle, the larger the field of view and the smaller objects appear in the scene. For an illustration, see Camera Graphics Terminology.

Example: ax.CameraViewAngle = 15

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Selection mode for the CameraViewAngle property, specified as one of these values:

  • 'auto' — Automatically select the field of view as the minimum angle that captures the entire scene, up to 180 degrees.

  • 'manual' — Manually specify the field of view. To specify a value, set the CameraViewAngle property.

Interactivity

expand all

Data exploration toolbar, which is an AxesToolbar object. Add a toolbar to the top-right corner of the axes for quick access to data exploration tools. The toolbar typically includes options to brush data, add data tips, rotate, pan, and zoom.

To add the toolbar, set the Visible property of the AxesToolbar object to 'on'. Some axes toolbar options are redundant with the figure toolbar. You can remove the redundant options from the figure toolbar using the removeToolbarExplorationButtons command.

ax = gca;
ax.Toolbar.Visible = 'on';
removeToolbarExplorationButtons(gcf)
To restore the figure toolbar exploration buttons, use the addToolbarExplorationButtons(gcf) command.

State of visibility, specified as one of these values:

  • 'on' — Display the object.

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

Location of mouse pointer, specified as a 2-by-3 array. The CurrentPoint property contains the (x,y,z) coordinates of the mouse pointer with respect to the axes. The returned array is of the form:

[xfront yfront zfront
 xback  yback  zback]

The two points indicate the location of the last mouse click. Howevever, if the figure has a WindowButtonMotionFcn callback defined, then the points indicate the last location of the mouse pointer. The figure also has a CurrentPoint property.

The values of the current point when using perspective projection can be different from the same point in orthographic projection because the shape of the axes volume can be different.

Orthogonal Projection

When using orthogonal projection, the values depend on whether the click is within the axes or outside the axes.

  • If the click is inside the axes, the two points lie on the line that is perpendicular to the plane of the screen and that passes through the pointer. The coordinates are the points where this line intersects the front and back surfaces of the axes volume (which is defined by the axes x, y, and z limits). The first row is the point nearest to the camera position. The second row is the point farthest from the camera position. This is true for both 2-D and 3-D views.

  • If the click is outside the axes, but within the figure, then the points lie on a line that passes through the pointer and is perpendicular to the camera target and camera position planes. The first row is the point in the camera position plane. The second row is the point in the plane of the camera target.

Perspective Projection

Clicking outside of the Axes object in perspective projection returns the front point as the current camera position. Only the back point updates with the coordinates of a point that lies on a line extending from the camera position through the pointer and intersecting the camera target at that point.

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

Note

If the PickableParts property is set to 'none' or if the HitTest property is set to 'off', then the context menu does not appear.

Selection state, specified as one of these values:

  • 'on' — Selected. If you click the object when in plot edit mode, then MATLAB sets its Selected property to 'on'. If the SelectionHighlight property also is set to 'on', then MATLAB displays selection handles around the object.

  • 'off' — Not selected.

Display of selection handles when selected, specified as one of these values:

  • 'on' — Display selection handles when the Selected property is set to 'on'.

  • 'off' — Never display selection handles, even when the Selected property is set to 'on'.

Callbacks

expand all

Mouse-click callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code when you click the object. If you specify this property using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • Clicked object — Access properties of the clicked object from within the callback function.

  • Event data — Empty argument. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

For more information on how to use function handles to define callback functions, see Callback Definition.

Note

If the PickableParts property is set to 'none' or if the HitTest property is set to 'off', then this callback does not execute.

Creation callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code when you create the object. MATLAB executes the callback after creating the object and setting all of its properties. Setting the CreateFcn property on an existing object has no effect. To have an effect, you must specify the CreateFcn property during object creation. One way to specify the property during object creation is to set the default property value for the object. See Default Property Values for more information.

If you specify this callback using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • Created object — Access properties of the object from within the callback function. You also can access the object through the CallbackObject property of the root, which can be queried using the gcbo function.

  • Event data — Empty argument. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

For more information on how to use function handles to define callback functions, see Callback Definition.

Deletion callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • Character vector that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code when you delete the object MATLAB executes the callback before destroying the object so that the callback can access its property values.

If you specify this callback using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • Deleted object — Access properties of the object from within the callback function. You also can access the object through the CallbackObject property of the root, which can be queried using the gcbo function.

  • Event data — Empty argument. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

For more information on how to use function handles to define callback functions, see Callback Definition.

Callback Execution Control

expand all

Callback interruption, specified as 'on' or 'off'. The Interruptible property determines if a running callback can be interrupted.

Note

Consider these callback states where:

  • The running callback is the currently executing callback.

  • The interrupting callback is a callback that tries to interrupt the running callback.

Whenever MATLAB invokes a callback, that callback attempts to interrupt a running callback. The Interruptible property of the object owning the running callback determines if interruption is permitted. If interruption is not permitted, then the BusyAction property of the object owning the interrupting callback determines if it is discarded or put in the queue.

The Interruptible property determines if another callback can interrupt the ButtonDownFcn callback of the Axes object. The Interruptible property has two values:

  • 'on' — Interruptible. Interruption occurs at the next point where MATLAB processes the queue. For example, when you have a command such as drawnow, figure, getframe, waitfor, or pause.

    • If the running callback contains one of these commands, then MATLAB stops the execution of the callback at this point and executes the interrupting callback. MATLAB resumes executing the running callback when the interrupting callback completes. For more information, see Interrupt Callback Execution.

    • If the running callback does not contain one of these commands, then MATLAB finishes executing the callback without interruption.

  • 'off' — Not interruptible. MATLAB finishes executing the running callback without any interruptions.

Callback queuing specified as 'queue' or 'cancel'. The BusyAction property determines how MATLAB handles the execution of interrupting callbacks.

Consider these callback states where:

  • The running callback is the currently executing callback.

  • The interrupting callback is a callback that tries to interrupt the running callback.

Whenever MATLAB invokes a callback, that callback attempts to interrupt a running callback. The Interruptible property of the object owning the running callback determines if interruption is permitted. If interruption is not permitted, then the BusyAction property of the object owning the interrupting callback determines if it is discarded or put in the queue.

If a callback of the Axes object tries to interrupt a running callback that cannot be interrupted, then the BusyAction property determines if it is discarded or put in the queue. Specify the BusyAction property as one of these values:

  • 'queue' — Put the interrupting callback in a queue to be processed after the running callback finishes execution. (default behavior)

  • 'cancel' — Discard the interrupting callback.

Ability to capture mouse clicks, specified as one of these values:

  • 'visible' — Capture mouse clicks only when visible. The Visible property must be set to 'on'. The HitTest property determines if the Axes object responds to the click or if an ancestor does.

  • 'all' — Capture mouse clicks regardless of visibility. The Visible property can be set to 'on' or 'off'. The HitTest property determines if the Axes object responds to the click or if an ancestor does.

  • 'none' — Cannot capture mouse clicks. Clicking the Axes object passes the click to the object below it in the current view of the figure window, which is typically the axes or the figure. The HitTest property has no effect.

If you want an object to be clickable when it is underneath other objects that you do not want to be clickable, then set the PickableParts property of the other objects to 'none' so that the click passes through them.

Response to captured mouse clicks, specified as one of these values:

  • 'on' — Trigger the ButtonDownFcn callback of the Axes object. If you have defined the UIContextMenu property, then invoke the context menu.

  • 'off' — Trigger the callbacks for the nearest ancestor of the Axes object that has:

    • HitTest property set to 'on'

    • PickableParts property set to a value that enables the ancestor to capture mouse clicks.

Note

The PickableParts property determines if the Axes object can capture mouse clicks. If it cannot, then the HitTest property has no effect.

This property is read-only.

Deletion status, returned as 'off' or 'on'. MATLAB sets the BeingDeleted property to 'on' when the delete function of the object begins execution (see the DeleteFcn property). The BeingDeleted property remains set to 'on' until the object no longer exists.

Check the value of the BeingDeleted property if you need to verify that the object is not about to be deleted before querying or modifying it.

Parent/Child

expand all

Parent, specified as Figure object, Panel object, or Tab object.

Children, returned as an array of graphics objects. Use this property to view a list of the children or to reorder the children by setting the property to a permutation of itself.

You cannot add or remove children using the Children property. To add a child to this list, set the Parent property of the child graphics object to the Axes object.

Visibility of the object handle in the Children property of the parent, specified as one of these values:

  • 'on' — Object handle is always visible.

  • 'off' — Object handle is invisible at all times. This option is useful for preventing unintended changes to the UI by another function. Set the HandleVisibility to 'off' to temporarily hide the handle during the execution of that function.

  • 'callback' — Object handle is visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line. This option blocks access to the object at the command line, but permits callback functions to access it.

If the object is not listed in the Children property of the parent, then functions that obtain object handles by searching the object hierarchy or querying handle properties cannot return it. For example, when you have a function such as get, findobj, gca, gcf, gco, newplot, cla, clf, and close.

Hidden object handles are still valid. Set the root ShowHiddenHandles property to 'on' to list all object handles regardless of their HandleVisibility property setting.

Identifiers

expand all

This property is read-only.

Type of graphics object returned as 'axes'.

Tag to associate with the axes object, specified as a character vector or string scalar.

Use this property to find axes objects in a hierarchy. For example, you can use the findobj function to find axes objects that have a specific Tag property value.

Example: 'January Data'

User data to associate with the axes object, specified as any MATLAB data, for example, a scalar, vector, matrix, cell array, character array, table, or structure. MATLAB does not use this data.

To associate multiple sets of data or to attach a field name to the data, use the getappdata and setappdata functions.

Example: 1:100

Introduced before R2006a

Was this topic helpful?