Axes appearance and behavior - MATLAB (2024)

Table of Contents
Font FontSize — Font size scalar numeric value FontSizeMode — Selection mode for font size 'auto' (default) | 'manual' LabelFontSizeMultiplier — Scale factor for label font size 1.1 (default) | numeric value greater than 0 TitleFontSizeMultiplier — Scale factor for title font size 1.1 (default) | numeric value greater than 0 SubtitleFontWeight — Subtitle character thickness 'normal' (default) | 'bold' Ticks XTick, YTick, ZTick — Tick values [] (default) | vector of increasing values XTickMode, YTickMode, ZTickMode — Selection mode for tick values 'auto' (default) | 'manual' XTickLabel, YTickLabel, ZTickLabel — Tick labels '' (default) | cell array of character vectors | string array | categorical array XTickLabelMode, YTickLabelMode, ZTickLabelMode — Selection mode for tick labels 'auto' (default) | 'manual' XTickLabelRotation, YTickLabelRotation, ZTickLabelRotation — Tick label rotation 0 (default) | numeric value in degrees XTickLabelRotationMode, YTickLabelRotationMode, ZTickLabelRotationMode — Selection mode for tick label rotation 'auto' (default) | 'manual' XMinorTick, YMinorTick, ZMinorTick — Minor tick marks on/off logical value TickDir — Tick mark direction 'in' (default) | 'out' | 'both' | 'none' TickLength — Tick mark length [0.01 0.025] (default) | two-element vector Rulers XLimMode, YLimMode, ZLimMode — Selection mode for axis limits 'auto' (default) | 'manual' XLimitMethod, YLimitMethod, ZLimitMethod — Axis limit selection method'tickaligned' (default) | 'tight' | 'padded' XAxis, YAxis, ZAxis — Axis ruler ruler object XAxisLocation — x-axis location 'bottom' (default) | 'top' | 'origin' YAxisLocation — y-axis location 'left' (default) | 'right' | 'origin' XColor, YColor, ZColor — Color of axis line, tick values, and labels [0.15 0.15 0.15] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... XColorMode — Property for setting x-axis grid color 'auto' (default) | 'manual' YColorMode — Property for setting y-axis grid color 'auto' (default) | 'manual' ZColorMode — Property for setting z-axis grid color 'auto' (default) | 'manual' XDir — x-axis direction 'normal' (default) | 'reverse' YDir — y-axis direction 'normal' (default) | 'reverse' ZDir — z-axis direction 'normal' (default) | 'reverse' Grids XGrid, YGrid, ZGrid — Grid lines 'off' (default) | on/off logical value GridLineWidth — Grid line width 0.5 (default) | positive number GridLineWidthMode — How grid line width is set "auto" (default) | "manual" GridColor — Color of grid lines [0.15 0.15 0.15] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... GridColorMode — Property for setting grid color 'auto' (default) | 'manual' XMinorGrid, YMinorGrid, ZMinorGrid — Minor grid lines 'off' (default) | on/off logical value MinorGridLineStyle — Line style for minor grid lines ':' (default) | '-' | '--' | '-.' | 'none' MinorGridLineWidth — Minor grid line width 0.5 (default) | positive number MinorGridLineWidthMode — How minor grid line width is set "auto" (default) | "manual" MinorGridColor — Color of minor grid lines [0.1 0.1 0.1] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... MinorGridColorMode — Property for setting minor grid color 'auto' (default) | 'manual' Labels Title — Text object for title text object Subtitle — Text object for subtitle text object TitleHorizontalAlignment — Title and subtitle horizontal alignment 'center' (default) | 'left' | 'right' XLabel, YLabel, ZLabel — Text object for axis label text object Legend — Legend associated with axes empty GraphicsPlaceholder (default) | Legend object Multiple Plots LineStyleCyclingMethod — How to cycle through line styles "aftercolor" (default) | "beforecolor" | "withcolor" NextSeriesIndex — SeriesIndex value for next object whole number Color and Transparency Maps Colormap — Color map parula (default) | m-by-3 array of RGB triplets ColorScale — Scale for color mapping'linear' (default) | 'log' CLim — Color limits [0 1] (default) | two-element vector of the form [cmin cmax] Alphamap — Transparency map array of 64 values from 0 to 1 (default) | array of finite alpha values from 0 to 1 AlphaScale — Scale for transparency mapping 'linear' (default) | 'log' ALim — Alpha limits [0 1] (default) | two-element vector of the form [amin amax] Box Styling Color — Background color [1 1 1] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... LineWidth — Line width 0.5 (default) | positive numeric value Box — Box outline 'off' (default) | on/off logical value BoxStyle — Box outline style 'back' (default) | 'full' Clipping — Clipping of objects to axes limits 'on' (default) | on/off logical value ClippingStyle — Clipping boundaries '3dbox' (default) | 'rectangle' AmbientLightColor — Background light color [1 1 1] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... Position InnerPosition — Inner size and location [0.1300 0.1100 0.7750 0.8150] (default) | four-element vector TightInset — Margins for text labels four-element vector of the form [left bottom right top] PositionConstraint — Position to hold constant "outerposition" | "innerposition" DataAspectRatio — Relative length of data units [1 1 1] (default) | three-element vector of the form [dx dy dz] DataAspectRatioMode — Data aspect ratio mode 'auto' (default) | 'manual' PlotBoxAspectRatio — Relative length of each axis [1 1 1] (default) | three-element vector of the form [px py pz] PlotBoxAspectRatioMode — Selection mode for PlotBoxAspectRatio 'auto' (default) | 'manual' Layout — Layout options empty LayoutOptions array (default) | TiledChartLayoutOptions object | GridLayoutOptions object View View — Azimuth and elevation of view [0 90] (default) | two-element vector of the form [azimuth elevation] Projection — Type of projection onto 2-D screen 'orthographic' (default) | 'perspective' CameraPosition — Camera location three-element vector of the form [x y z] CameraPositionMode — Selection mode for CameraPosition 'auto' (default) | 'manual' CameraTarget — Camera target point three-element vector of the form [x y z] CameraTargetMode — Selection mode for CameraTarget 'auto' (default) | 'manual' CameraUpVector — Vector defining upwards direction three-element direction vector of the form [x y z] CameraUpVectorMode — Selection mode for CameraUpVector 'auto' (default) | 'manual' CameraViewAngle — Field of view 6.6086 (default) | scalar angle in range [0,180) CameraViewAngleMode — Selection mode for CameraViewAngle 'auto' (default) | 'manual' Interactivity Toolbar — Data exploration toolbar AxesToolbar object (default) Interactions — Interactions array of interaction objects | [] Visible — State of visibility 'on' (default) | on/off logical value CurrentPoint — Location of mouse pointer 2-by-3 array Callbacks Callback Execution Control Parent/Child Parent — Parent container Figure object | Panel object | Tab object | TiledChartLayout object | GridLayout object Identifiers Type — Type of graphics object 'axes' Version History R2023a: Control cycling of line styles using the LineStyleCyclingMethod property R2023a: Specify grid line thickness using the GridLineWidth and MinorGridLineWidth properties R2022a: The FontSmoothing property will have no effect in a future release R2022a: Control tick label rotation using the XTickLabelRotationMode, YTickLabelRotationMode, and ZTickLabelRotationMode properties R2021b: Remove tick marks by setting the TickDir property to "none" R2021a: Control axis limits with the XLimitMethod, YLimitMethod, and ZLimitMethod properties R2020b: Control the alignment of a plot title with the TitleHorizontalAlignment property R2020b: Create and style subtitles with the Subtitle and SubtitleFontWeight properties R2020a: Preserve inner or outer position with the PositionConstraint property R2020a: UIContextMenu property is not recommended R2019b: Position axes within tiled chart layouts using the Layout property R2019a: Customize chart interactions using the Interactions property R2018a: Add a toolbar to the axes with the Toolbar property See Also Topics MATLAB Command Americas Europe Asia Pacific

Axes appearance and behavior

expand all in page

Axes properties control the appearance and behavior of an Axes object. By changing property values, you can modify certain aspects of the axes. Use dot notation to query and set properties.

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

Font

expand all

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.

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.

Subtitle character thickness, specified as one of these values:

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

  • 'bold' — Thicker characters than normal

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, string array, or categorical 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 tick values, then the labels repeat.

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

If you specify this property as a categorical array, MATLAB uses the values in the array, not the categories.

As an alternative to setting this property, you can use the xticklabels, yticklabels, and zticklabels functions. For an example, see Specify Axis Tick Values and Labels.

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

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 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.

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

  • 'auto' — Automatically select the tick label rotation.

  • 'manual' — Use a tick label rotation that you specify. To specify the rotation, set the XTickLabelRotation, YTickLabelRotation, or ZTickLabelRotation property.

Minor tick marks, 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 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.

  • 'off' — Do not display minor tick marks. This value is the default for an axis with a linear 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.

  • 'none' — Do not display any tick marks.

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

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

  • 'auto' — Enable automatic limit selection, which is based on the total span of the plotted data and the value of the XLimitMethod, YLimitMethod, or ZLimitMethod property.

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

Example: ax.XLimMode = 'auto'

Axis limit selection method, specified as a value from the table. The examples in the table show the approximate appearance for different values of the XLimitMethod property. Your results might differ depending on your data, the size of the axes, and the type of plot you create.

ValueDescriptionExample (XLimitMethod)
'tickaligned'

In general, align the edges of the axes box with the tick marks that are closest to your data without excluding any data. The appearance might vary depending on the type of data you plot and the type of chart you create.

Axes appearance and behavior - MATLAB (1)

'tight'

Fit the axes box tightly around the data by setting the axis limits equal to the range of the data.

Axes appearance and behavior - MATLAB (2)

'padded'

Fit the axes box around the data with a thin margin of padding on each side. The width of the margin is approximately 7% of your data range.

Axes appearance and behavior - MATLAB (3)

Note

The axis limit method has no effect when the corresponding mode property (XLimMode, YLimMode, or ZLimMode) is set to 'manual'.

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 that Axes objects support, see:

  • NumericRuler Properties

  • DatetimeRuler Properties

  • DurationRuler Properties

  • CategoricalRuler Properties

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'

Axes appearance and behavior - MATLAB (4)

'top'

Top of the axes.

Example: ax.XAxisLocation = 'top'

Axes appearance and behavior - MATLAB (5)

'origin'

Through the origin point (0,0).

Example: ax.XAxisLocation = 'origin'

Axes appearance and behavior - MATLAB (6)

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'

Axes appearance and behavior - MATLAB (7)

'right'

Right side of the axes.

Example: ax.YAxisLocation = 'right'

Axes appearance and behavior - MATLAB (8)

'origin'

Through the origin point (0,0).

Example: ax.YAxisLocation = 'origin'

Axes appearance and behavior - MATLAB (9)

Color of the axis line, tick values, and labels in the x, y, or z direction, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. The color you specify 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 or a hexadecimal color code.

  • 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].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Axes appearance and behavior - MATLAB (10)

"green""g"[0 1 0]"#00FF00"

Axes appearance and behavior - MATLAB (11)

"blue""b"[0 0 1]"#0000FF"

Axes appearance and behavior - MATLAB (12)

"cyan" "c"[0 1 1]"#00FFFF"

Axes appearance and behavior - MATLAB (13)

"magenta""m"[1 0 1]"#FF00FF"

Axes appearance and behavior - MATLAB (14)

"yellow""y"[1 1 0]"#FFFF00"

Axes appearance and behavior - MATLAB (15)

"black""k"[0 0 0]"#000000"

Axes appearance and behavior - MATLAB (16)

"white""w"[1 1 1]"#FFFFFF"

Axes appearance and behavior - MATLAB (17)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Axes appearance and behavior - MATLAB (18)

[0.8500 0.3250 0.0980]"#D95319"

Axes appearance and behavior - MATLAB (19)

[0.9290 0.6940 0.1250]"#EDB120"

Axes appearance and behavior - MATLAB (20)

[0.4940 0.1840 0.5560]"#7E2F8E"

Axes appearance and behavior - MATLAB (21)

[0.4660 0.6740 0.1880]"#77AC30"

Axes appearance and behavior - MATLAB (22)

[0.3010 0.7450 0.9330]"#4DBEEE"

Axes appearance and behavior - MATLAB (23)

[0.6350 0.0780 0.1840]"#A2142F"

Axes appearance and behavior - MATLAB (24)

Example: ax.XColor = [1 1 0]

Example: ax.YColor = 'y'

Example: ax.ZColor = 'yellow'

Example: ax.ZColor = '#FFFF00'

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 y-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'

Axes appearance and behavior - MATLAB (25)

Axes appearance and behavior - MATLAB (26)

'reverse'

Values increase from right to left.

Example: ax.XDir = 'reverse'

Axes appearance and behavior - MATLAB (27)

Axes appearance and behavior - MATLAB (28)

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'

Axes appearance and behavior - MATLAB (29)

Axes appearance and behavior - MATLAB (30)

'reverse'

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

Example: ax.YDir = 'reverse'

Axes appearance and behavior - MATLAB (31)

Axes appearance and behavior - MATLAB (32)

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'

Axes appearance and behavior - MATLAB (33)

'reverse'

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

Example: ax.ZDir = 'reverse'

Axes appearance and behavior - MATLAB (34)

Grids

expand all

Grid lines, 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 grid lines perpendicular to the axis; for example, along lines of constant x, y, or z values.

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

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'

Since R2023a

Grid line width, specified as a positive number. Set this property or the MinorGridLineWidth property to control the thickness of the grid lines independently of the box outline and tick marks.

Example

Create vectors x and y, and plot them. Display the grid lines in the axes by calling grid on. Increase the thickness of the grid lines, box outline, and tick marks by setting the LineWidth property of the axes to 1.5.

x = linspace(0,10);y = sin(x);plot(x,y)grid onax = gca;ax.LineWidth = 1.5;

Axes appearance and behavior - MATLAB (35)

Make the grid lines thinner by setting the grid line width to 0.5.

ax.GridLineWidth = 0.5;

Axes appearance and behavior - MATLAB (36)

Since R2023a

How the grid line width is set, specified as one of these values:

  • "auto" — Set the GridLineWidth property to the same value as the LineWidth property.

  • "manual" — Hold the current value of the GridLineWidth property.

MATLAB sets this property to "manual" when you explicitly set the GridLineWidth property to a value.

Color of grid lines, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • 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].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Axes appearance and behavior - MATLAB (37)

"green""g"[0 1 0]"#00FF00"

Axes appearance and behavior - MATLAB (38)

"blue""b"[0 0 1]"#0000FF"

Axes appearance and behavior - MATLAB (39)

"cyan" "c"[0 1 1]"#00FFFF"

Axes appearance and behavior - MATLAB (40)

"magenta""m"[1 0 1]"#FF00FF"

Axes appearance and behavior - MATLAB (41)

"yellow""y"[1 1 0]"#FFFF00"

Axes appearance and behavior - MATLAB (42)

"black""k"[0 0 0]"#000000"

Axes appearance and behavior - MATLAB (43)

"white""w"[1 1 1]"#FFFFFF"

Axes appearance and behavior - MATLAB (44)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Axes appearance and behavior - MATLAB (45)

[0.8500 0.3250 0.0980]"#D95319"

Axes appearance and behavior - MATLAB (46)

[0.9290 0.6940 0.1250]"#EDB120"

Axes appearance and behavior - MATLAB (47)

[0.4940 0.1840 0.5560]"#7E2F8E"

Axes appearance and behavior - MATLAB (48)

[0.4660 0.6740 0.1880]"#77AC30"

Axes appearance and behavior - MATLAB (49)

[0.3010 0.7450 0.9330]"#4DBEEE"

Axes appearance and behavior - MATLAB (50)

[0.6350 0.0780 0.1840]"#A2142F"

Axes appearance and behavior - MATLAB (51)

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'

Example: ax.GridColor = '#0000FF'

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.

Minor grid lines, 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 grid lines aligned with the minor tick marks of the axis. You do not need to enable minor ticks to display minor grid lines.

  • 'off' — Do not display 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

Axes appearance and behavior - MATLAB (52)

"--"Dashed line

Axes appearance and behavior - MATLAB (53)

":"Dotted line

Axes appearance and behavior - MATLAB (54)

"-."Dash-dotted line

Axes appearance and behavior - MATLAB (55)

"none"No lineNo line

To display minor grid lines, use the grid minor command or set the XMinorGrid, YMinorGrid, or ZMinorGrid property to 'on'.

Example: ax.MinorGridLineStyle = '-.'

Since R2023a

Minor grid line width, specified as a positive number. Set this property or the GridLineWidth property to control the thickness of the grid lines independently of the box outline and tick marks.

Tip

  • To see the minor grid lines, set the XMinorGrid, YMinorGrid, or ZMinorGrid properties to "on".

  • When you set the GridLineWidth property, MATLAB also sets the MinorGridLineWidth property to the same value. To avoid changing the MinorGridLineWidth property, set the MinorGridLineWidthMode property to "manual" before setting the GridLineWidth property.

Since R2023a

How the minor grid line width is set, specified as one of these values:

  • "auto" — Set the MinorGridLineWidth property to the same value as the GridLineWidth property.

  • "manual" — Hold the current value of the MinorGridLineWidth property.

MATLAB sets this property to "manual" when you explicitly set the MinorGridLineWidth property to a value.

Color of minor grid lines, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • 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].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Axes appearance and behavior - MATLAB (56)

"green""g"[0 1 0]"#00FF00"

Axes appearance and behavior - MATLAB (57)

"blue""b"[0 0 1]"#0000FF"

Axes appearance and behavior - MATLAB (58)

"cyan" "c"[0 1 1]"#00FFFF"

Axes appearance and behavior - MATLAB (59)

"magenta""m"[1 0 1]"#FF00FF"

Axes appearance and behavior - MATLAB (60)

"yellow""y"[1 1 0]"#FFFF00"

Axes appearance and behavior - MATLAB (61)

"black""k"[0 0 0]"#000000"

Axes appearance and behavior - MATLAB (62)

"white""w"[1 1 1]"#FFFFFF"

Axes appearance and behavior - MATLAB (63)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Axes appearance and behavior - MATLAB (64)

[0.8500 0.3250 0.0980]"#D95319"

Axes appearance and behavior - MATLAB (65)

[0.9290 0.6940 0.1250]"#EDB120"

Axes appearance and behavior - MATLAB (66)

[0.4940 0.1840 0.5560]"#7E2F8E"

Axes appearance and behavior - MATLAB (67)

[0.4660 0.6740 0.1880]"#77AC30"

Axes appearance and behavior - MATLAB (68)

[0.3010 0.7450 0.9330]"#4DBEEE"

Axes appearance and behavior - MATLAB (69)

[0.6350 0.0780 0.1840]"#A2142F"

Axes appearance and behavior - MATLAB (70)

To display minor grid lines, use the grid minor command or set the XMinorGrid, YMinorGrid, or ZMinorGrid property to 'on'.

Example: ax.MinorGridColor = [0 0 1]

Example: ax.MinorGridColor = 'b'

Example: ax.MinorGridColor = 'blue'

Example: ax.MinorGridColor = '#0000FF'

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 minor grid line color for all directions.

Labels

expand all

Text object for the 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 the axes subtitle. To add a subtitle, set the String property of the text object. To change its appearance, such as the font angle, set other properties. For a complete list, see Text Properties.

ax = gca;ax.Subtitle.String = 'An Insightful Subtitle';ax.Subtitle.FontAngle = 'italic';

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

subtitle('An Insightful Subtitle','FontAngle','italic')

Or use the title function, and specify two character vector input arguments and two output arguments. Then set properties on the second text object returned by the function.

[t,s] = title('Clever Title','An Insightful Subtitle');s.FontAngle = 'italic';

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.

Title and subtitle horizontal alignment with the plot box, specified as one of the values from the table.

TitleHorizontalAlignment ValueDescriptionAppearance
'center'The title and subtitle are centered over the plot box.

Axes appearance and behavior - MATLAB (71)

'left'The title and subtitle are aligned with the left side of the plot box.

Axes appearance and behavior - MATLAB (72)

'right'The title and subtitle are aligned with the right side of the plot box.

Axes appearance and behavior - MATLAB (73)

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.Legendif ~isempty(lgd) disp('Legend Exists')end

Multiple Plots

expand all

Since R2023a

How to cycle through the line styles when there are multiple lines in the axes, specified as one of the values from this table.

The examples in this table were created using the default colors in the ColorOrder property and three line styles (["-","-o","--"]) in the LineStyleOrder property.

ValueDescriptionExample

"aftercolor"

Cycle through the line styles of the LineStyleOrder after the colors of the ColorOrder.

Axes appearance and behavior - MATLAB (74)

"beforecolor"

Cycle through the line styles of the LineStyleOrder before the colors of the ColorOrder.

Axes appearance and behavior - MATLAB (75)

"withcolor"

Cycle through the line styles of the LineStyleOrder with the colors of the ColorOrder.

Axes appearance and behavior - MATLAB (76)

This property is read-only.

SeriesIndex value for the next plot object added to the axes, returned as a whole number greater than or equal to 0. This property is useful when you want to track how the objects cycle through the colors and line styles. This property maintains a count of the objects in the axes that have a numeric SeriesIndex property value. MATLAB uses it to assign a SeriesIndex value to each new object. The count starts at 1 when you create the axes, and it increases by 1 for each additional object. Thus, the count is typically n+1, where n is the number of objects in the axes.

If you manually change the ColorOrderIndex or LineStyleOrderIndex property on the axes, the value of the NextSeriesIndex property changes to 0. As a consequence, objects that have a SeriesIndex property no longer update automatically when you change the ColorOrder or LineStyleOrder properties on the axes.

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.

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.

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. An alphamap can be any length.

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

  • 'linear' — Linear scale

  • 'log' — Log scale

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.

Box Styling

expand all

Background color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • 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].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Axes appearance and behavior - MATLAB (77)

"green""g"[0 1 0]"#00FF00"

Axes appearance and behavior - MATLAB (78)

"blue""b"[0 0 1]"#0000FF"

Axes appearance and behavior - MATLAB (79)

"cyan" "c"[0 1 1]"#00FFFF"

Axes appearance and behavior - MATLAB (80)

"magenta""m"[1 0 1]"#FF00FF"

Axes appearance and behavior - MATLAB (81)

"yellow""y"[1 1 0]"#FFFF00"

Axes appearance and behavior - MATLAB (82)

"black""k"[0 0 0]"#000000"

Axes appearance and behavior - MATLAB (83)

"white""w"[1 1 1]"#FFFFFF"

Axes appearance and behavior - MATLAB (84)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Axes appearance and behavior - MATLAB (85)

[0.8500 0.3250 0.0980]"#D95319"

Axes appearance and behavior - MATLAB (86)

[0.9290 0.6940 0.1250]"#EDB120"

Axes appearance and behavior - MATLAB (87)

[0.4940 0.1840 0.5560]"#7E2F8E"

Axes appearance and behavior - MATLAB (88)

[0.4660 0.6740 0.1880]"#77AC30"

Axes appearance and behavior - MATLAB (89)

[0.3010 0.7450 0.9330]"#4DBEEE"

Axes appearance and behavior - MATLAB (90)

[0.6350 0.0780 0.1840]"#A2142F"

Axes appearance and behavior - MATLAB (91)

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

Example: ax.Color = 'b';

Example: ax.Color = 'blue';

Example: ax.Color = '#0000FF';

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 '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.

ValueDescription2-D Result3-D Result
'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'

Axes appearance and behavior - MATLAB (92)

Axes appearance and behavior - MATLAB (93)

'off'

Do not display the box outline around the axes.

Example: ax.Box = 'off'

Axes appearance and behavior - MATLAB (94)

Axes appearance and behavior - MATLAB (95)

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'

Axes appearance and behavior - MATLAB (96)

'full'

Outline the entire 3-D box.

Example: ax.BoxStyle = 'full'

Axes appearance and behavior - MATLAB (97)

Clipping of objects to the axes limits, 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.

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.

Axes appearance and behavior - MATLAB (98)

'rectangle'

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

Clip thick lines at the axes limits.

Axes appearance and behavior - MATLAB (99)

Background light color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. 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 or a hexadecimal color code.

  • 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].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Axes appearance and behavior - MATLAB (100)

"green""g"[0 1 0]"#00FF00"

Axes appearance and behavior - MATLAB (101)

"blue""b"[0 0 1]"#0000FF"

Axes appearance and behavior - MATLAB (102)

"cyan" "c"[0 1 1]"#00FFFF"

Axes appearance and behavior - MATLAB (103)

"magenta""m"[1 0 1]"#FF00FF"

Axes appearance and behavior - MATLAB (104)

"yellow""y"[1 1 0]"#FFFF00"

Axes appearance and behavior - MATLAB (105)

"black""k"[0 0 0]"#000000"

Axes appearance and behavior - MATLAB (106)

"white""w"[1 1 1]"#FFFFFF"

Axes appearance and behavior - MATLAB (107)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Axes appearance and behavior - MATLAB (108)

[0.8500 0.3250 0.0980]"#D95319"

Axes appearance and behavior - MATLAB (109)

[0.9290 0.6940 0.1250]"#EDB120"

Axes appearance and behavior - MATLAB (110)

[0.4940 0.1840 0.5560]"#7E2F8E"

Axes appearance and behavior - MATLAB (111)

[0.4660 0.6740 0.1880]"#77AC30"

Axes appearance and behavior - MATLAB (112)

[0.3010 0.7450 0.9330]"#4DBEEE"

Axes appearance and behavior - MATLAB (113)

[0.6350 0.0780 0.1840]"#A2142F"

Axes appearance and behavior - MATLAB (114)

Example: ax.AmbientLightColor = [1 0 1]

Example: ax.AmbientLightColor = 'm'

Example: ax.AmbientLightColor = 'magenta'

Example: ax.AmbientLightColor = '#FF00FF'

Position

expand all

Inner size and location, specified as a four-element vector of the form [left bottom width height]. This property is equivalent to the Position property.

Note

  • When querying the inner position of axes with constrained aspect ratios (such square axes or those containing images) consider using the tightPosition function for more accuracy. (since R2022b)

  • Setting this property has no effect when the parent container is a TiledChartLayout

This property is read-only.

Margins for the text labels, returned as a four-element vector of the form [left bottom right top]. By default, MATLAB measures 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

Axes appearance and behavior - MATLAB (115)

Axes appearance and behavior - MATLAB (116)

For more information, see Control Axes Layout.

Position property to hold constant when adding, removing, or changing decorations, specified as one of the following values:

  • "outerposition" — The OuterPosition property remains constant when you add, remove, or change decorations such as a title or an axis label. If any positional adjustments are needed, MATLAB adjusts the InnerPosition property.

  • "innerposition" — The InnerPosition property remains constant when you add, remove, or change decorations such as a title or an axis label. If any positional adjustments are needed, MATLAB adjusts the OuterPosition property.

Note

Setting this property has no effect when the parent container is a TiledChartLayout object.

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 plot box 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.

Layout options, specified as a TiledChartLayoutOptions or a GridLayoutOptions object. This property is useful when the axes object is either in a tiled chart layout or a grid layout.

To position the axes within the grid of a tiled chart layout, set the Tile and TileSpan properties on the TiledChartLayoutOptions object. For example, consider a 3-by-3 tiled chart layout. The layout has a grid of tiles in the center, and four tiles along the outer edges. In practice, the grid is invisible and the outer tiles do not take up space until you populate them with axes or charts.

Axes appearance and behavior - MATLAB (117)

This code places the axes ax in the third tile of the grid.

ax.Layout.Tile = 3;

To make the axes span multiple tiles, specify the TileSpan property as a two-element vector. For example, this axes spans 2 rows and 3 columns of tiles.

ax.Layout.TileSpan = [2 3];

To place the axes in one of the surrounding tiles, specify the Tile property as 'north', 'south', 'east', or 'west'. For example, setting the value to 'east' places the axes in the tile to the right of the grid.

ax.Layout.Tile = 'east';

To place the axes into a layout within an app, specify this property as a GridLayoutOptions object. For more information about working with grid layouts in apps, see uigridlayout.

If the axes is not a child of either a tiled chart layout or a grid layout (for example, if it is a child of a figure or panel) then this property is empty and has no effect.

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.

Note

Setting the azimuth and elevation angles might reset other camera-related properties. For best results, set the azimuth and elevation angles before setting other camera-related properties.

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. The toolbar appears at the top-right corner of the axes when you hover over it.

Axes appearance and behavior - MATLAB (118)

The toolbar buttons depend on the contents of the axes, but typically include zooming, panning, rotating, data tips, data brushing, and restoring the original view. You can customize the toolbar buttons using the axtoolbar and axtoolbarbtn functions.

If you do not want the toolbar to appear when you hover over the axes, set the Visible property of the AxesToolbar object to 'off'.

ax = gca;ax.Toolbar.Visible = 'off';

For more information, see AxesToolbar Properties.

Interactions, specified as an array of interaction objects or an empty array. The interactions you specify are available within your chart through gestures. You do not have to select any axes toolbar buttons to use them. For example, a panInteraction object enables dragging to pan within a chart. For a list of interaction objects, see Control Chart Interactivity.

The default set of interactions depends on the type of chart you are displaying. You can replace the default set with a new set of interactions, but you cannot access or modify any of the interactions in the default set. For example, this code replaces the default set of interactions with the panInteraction and zoomInteraction objects.

ax = gca;ax.Interactions = [panInteraction zoomInteraction];

To remove all interactions from the axes, set this property to an empty array. To temporarily disable the current set of interactions, call the disableDefaultInteractivity function. You can reenable them by calling the enableDefaultInteractivity function.

Note

Interaction objects are not returned by findobj or findall, and they are not copied by copyobj.

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 axes and its children.

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

Note

When the Visible property is 'off', the axes object is invisible, but child objects such as lines remain visible.

This property is read-only.

Location of mouse pointer, returned 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. However, 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.

Callbacks

expand all

Callback Execution Control

expand all

Parent/Child

expand all

Parent container, specified as a Figure, Panel, Tab, TiledChartLayout, or GridLayout object.

Identifiers

expand all

This property is read-only.

Type of graphics object returned as 'axes'.

Version History

Introduced before R2006a

expand all

Use the LineStyleCyclingMethod property to control how different lines are distinguished from one another in the axes.

Change the thickness of grid lines independently of the box outline and tick marks by setting the GridLineWidth and MinorGridLineWidth properties of the axes. Before R2023a, the LineWidth property of the axes was the only property for controlling the grid line width. However, that property controlled the grid lines, box outline, and tick marks together. Now you can control the thickness of the grid lines separately.

The FontSmoothing property will have no effect in a future release. Font smoothing will be enabled regardless of the value of the property.

Now you can control the selection mode for tick label rotation by setting the XTickLabelRotationMode, YTickLabelRotationMode, or ZTickLabelRotationMode property.

You can remove all the tick marks from the axes by setting the TickDir property to "none".

Control the axis limits for your plots by setting the XLimitMethod, YLimitMethod, or ZLimitMethod on the axes.

You can control the alignment of a plot title by setting the TitleHorizontalAlignment property of the axes to "left", "right", or "center".

Add a subtitle to your plot by setting the Subtitle property or calling the subtitle function. To control the appearance of the subtitle, set the SubtitleFontWeight property.

Set the PositionConstraint property of an Axes object to control the space around the plot box when you add or modify decorations such as titles and axis labels.

Use the Layout property to position an Axes object within a tiled chart layout.

You can create a customized set of chart interactions by setting the Interactions property of the axes. These interactions are built into the axes and are available without having to select any buttons in the axes toolbar. Some types of interactions are enabled by default, depending on the content of the axes.

Use the Toolbar property to add a toolbar to the top-right corner of the axes for quick access to data exploration tools.

See Also

axes | axis | gca | cla | box | grid

Topics

  • Access Property Values
  • Graphics Object Properties

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.

Axes appearance and behavior - MATLAB (119)

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

Axes appearance and behavior - MATLAB (2024)
Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 5602

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.