CategoricalRuler Properties

Control axis with categorical values

CategoricalRuler properties control the appearance and behavior of an x-axis, y-axis, or z-axis that shows categorical values. Each individual axis has its own ruler object. By changing property values of the ruler, you can modify certain aspects of a specific axis.

Use dot notation to refer to a particular ruler and property. Access the ruler objects through the XAxis, YAxis, and ZAxis properties of the Axes object. For example:

ax = gca;
co = ax.XAxis.Color;
ax.XAxis.Color = 'blue';

Appearance

expand all

Color of the axis line and labels, 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 character vector or a string scalar 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. Thus, 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'

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

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

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

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

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

'black''k'[0 0 0]'#000000'

'white''w'[1 1 1]'#FFFFFF'

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

[0.8500 0.3250 0.0980]'#D95319'

[0.9290 0.6940 0.1250]'#EDB120'

[0.4940 0.1840 0.5560]'#7E2F8E'

[0.4660 0.6740 0.1880]'#77AC30'

[0.3010 0.7450 0.9330]'#4DBEEE'

[0.6350 0.0780 0.1840]'#A2142F'

Note

The Color property for the ruler and the associated XColor, YColor, or ZColor property for the parent axes always have the same value. Setting one also sets the other.

Width of axis line and tick marks, specified as a positive value in point units. One point equals 1/72 inch.

Example: ax.XAxis.LineWidth = 2;

Note

Setting the LineWidth property for the parent axes sets the LineWidth property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Axis label, which is a text object. To display text or change existing text, set the String property for the text object. Use other properties to change the text appearance, such as the font style or color.

ax = gca;
ax.XAxis.Label.String = 'X Axis';
ax.XAxis.Label.FontSize = 12;

For a full list of options, see Text Properties.

Alternatively, add or modify the axis labels using the xlabel, ylabel, and zlabel functions.

Note

The text object is not a child of the ruler object, so it cannot be returned by findobj and it does not use the default text property values.

Axis visibility, specified as one of these values:

  • 'on' — Display the axis.

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

Example: ax.XAxis.Visible = 'off';

Scale and Direction

expand all

Scale of values along axis, specified as 'linear'.

Direction of increasing values, specified as one of these values:

  • 'normal' — Values increase from left to right or bottom to top.

  • 'reverse' — Values increase from right to left or top to bottom.

Note

The Direction property for the ruler and the associated XDir, YDir, or ZDir property for the parent axes always have the same value. Setting one also sets the other.

Example: ax.XAxis.Direction = 'reverse';

Tick Values and Labels

expand all

Categories plotted along the axis, specified as a cell array of character vectors, a categorical array, or a string array. Querying this property returns a cell array of character vectors. Set this property to exclude certain categories from appearing in the chart.

Example: ax.XAxis.Categories = categorical({'small','medium','large'}) specifies a categorical array.

Example: ax.XAxis.Categories = {'small','medium','large'} specifies a cell array.

Example: ax.XAxis.Categories = string({'small','medium','large'}) specifies a string array.

Example

Create a histogram with categories along the x-axis and query the Categories property. Then set the Categories property so that only a subset of categories appear along the axis.

A =  categorical({'r' 'b' 'g' 'g' 'r' 'b' 'b' 'r' 'g' 'y' 'g' 'm'});
h = histogram(A);
ax = gca;
ax.XAxis.Categories
ans = 

  1×5 categorical array

     b      g      m      r      y 
ax.XAxis.Categories = categorical({'b','m','y'});

Data Types: cell | categorical | string

First and last categories displayed along the axis, specified as a two-element vector indicating two category names. The categories must be two of the categories in the Categories property, and must appear in the same relative order that they appear in the Categories property.

Example: ax.XAxis.Categories = categorical({'small','medium'}) specifies a two-element categorical array.

Example: ax.XAxis.Categories = {'small','medium'} specifies a two-element cell array.

Example: ax.XAxis.Categories = string({'small','medium'}) specifies a two-element string array.

If you assign a value to this property, then MATLAB changes the associated LimitsMode property to 'manual'.

Alternatively, set the limits using the xlim, ylim, and zlim functions.

Note

The Limits property for the ruler and the associated XLim, YLim, or ZLim property for the parent axes always have the same value. Setting one also sets the other.

Example

Set the Limits property to only show the categories between 'b' and 'm' along the axis.

A =  categorical({'r' 'b' 'g' 'g' 'r' 'b' 'b' 'r' 'g' 'y' 'g' 'm'});
h = histogram(A);
ax = gca;
ax.XAxis.Limits = categorical({'b','m'});

Data Types: categorical | string | cell

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

  • 'auto' — Automatically select the axis limits based on the data plotted.

  • 'manual' — Use axis limit values that you specify. To specify the axis limits, set the Limits property.

Note

The LimitsMode property for the ruler and the associated XLimMode, YLimMode, or ZLimMode property for the parent axes always have the same value. Setting one also sets the other.

Tick mark locations along the axis, specified as a cell array of character vectors, a categorical array, or a string array indicating category names. The categories must be a subset of the categories in the Categories property and must appear in the same relative order that they appear in the Categories property. To remove all tick marks and labels along the axis, set this property to an empty array [].

Example: ax.XAxis.Categories = categorical({'small','medium','large'}) specifies a categorical array.

Example: ax.XAxis.Categories = {'small','medium','large'} specifies a cell array.

Example: ax.XAxis.Categories = string({'small','medium','large'}) specifies a string array.

If you assign a value to this property, then MATLAB sets the TickValuesMode property to 'manual'.

Alternatively, use the xticks, yticks, and zticks functions.

Note

The TickValues property for the ruler and the associated XTick, YTick, or ZTick property for the parent axes always have the same value. Setting one also sets the other.

Example

Label a subset of categories along the axis by setting the TickValues property to a subset of categories.

A =  categorical({'r' 'b' 'g' 'g' 'r' 'b' 'b' 'r' 'g' 'y' 'g' 'm'});
h = histogram(A);
ax = gca;
ax.XAxis.TickValues = categorical({'b','m','y'});

Data Types: categorical | string | cell

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

  • 'auto' — Automatically select the tick values based on the data plotted.

  • 'manual' — Use tick values that you specify. To specify the values, set the TickValues property.

Note

The TickValuesMode property for the ruler and the associated XTickMode, YTickMode, or ZTickMode property for the parent axes always have the same value. Setting one also sets the other.

Tick mark labels, specified as a cell array of character vectors, string array, or categorical array. Use this property to relabel the tick marks without changing the category names. If you do not specify a label for every value, then the labels repeat. The labels support TeX and LaTeX markup. See the TickLabelInterpreter property for more information.

If you set this property, then MATLAB sets the TickLabelsMode property to 'manual'.

Alternatively, specify the tick labels using the xticklabels, yticklabels, and zticklabels functions.

Note

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

  • The TickLabels property for the ruler and the associated XTickLabel, YTickLabel, or ZTickLabel property for the parent axes always have the same value. Setting one also sets the other.

Example

Relabel the categories along the x-axis.

A =  categorical({'r' 'b' 'g' 'g' 'r' 'b' 'b' 'r' 'g' 'y' 'g'});
h = histogram(A);
ax = gca;
ax.XAxis.TickLabels = {'Blue','Green','Red','Yellow'}

Data Types: char | string | categorical

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

  • 'auto' — Automatically select the tick labels.

  • 'manual' — Use tick labels that you specify. To specify the labels, set the TickLabels property.

Note

The TickLabelsMode property for the ruler and the associated XTickLabelMode, YTickLabelMode, or ZTickLabelMode property for the parent axes always have the same value. Setting one also sets the other.

Interpretation of tick label characters, specified as one of these values:

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

  • 'latex' — Interpret characters using LaTeX markup.

  • 'none' — Display literal characters.

Note

Setting the TickLabelInterpreter property for the parent axes sets the TickLabelInterpreter property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.XAxis.TickLabelInterpreter = 'latex';

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.

This table lists the supported modifiers with the TickLabelInterpreter property set to 'tex'. Modifiers remain in effect until the end of the text. Superscripts and subscripts are an exception because they 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 in combination 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 labels, 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. The FontName, FontWeight, and FontAngle properties do not have an effect. To change the font style, use LaTeX markup within the text. The maximum size of the text that you can use with the LaTeX interpreter is 1200 characters. For multiline text, the maximum size of the text reduces by about 10 characters per line.

For more information about the LaTeX system, see The LaTeX Project website at https://www.latex-project.org/.

Rotation of tick labels, specified as a scalar value in degrees. Positive values give counterclockwise rotation. Negative values give clockwise rotation.

Alternatively, you can rotate the tick labels using the xtickangle, ytickangle, and ztickangle functions.

Note

The TickLabelRotation property for the ruler and the associated XTickLabelRotation, YTickLabelRotation, or ZTickLabelRotation property for the parent axes always have the same value. Setting one also sets the other.

Example: ax.XAxis.TickLabelRotation = 45;

Example: ax.YAxis.TickLabelRotation = -45;

Selection mode for the TickLabelRotation property, 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 TickLabelRotation property.

Tick mark direction, specified as one of these values:

  • 'in' — Direct the tick marks inward from the axis lines. This is the default for 2-D views.

  • 'out' — Direct the tick marks outward from the axis lines. This is the default for 3-D views.

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

If you assign a value to this property, then MATLAB sets the TickDirectionMode property to 'manual'.

Note

Setting the TickDir property for the parent axes sets the TickDirection property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.YAxis.TickDirection = 'out';

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

  • 'auto' — Automatically select the tick direction.

  • 'manual' — Use a tick direction that you specify. To specify the tick direction, set the TickDirection property.

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. The second element is the tick mark length in 3-D views. Specify the values in units normalized relative to the longest axes dimension.

Note

Setting the TickLength property for the parent axes sets the TickLength property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.YAxis.TickLength = [0.02 0.035];

Minor tick mark display, specified as one of these values:

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

  • 'on' — Display minor tick marks between the major tick marks on the axis. This is the default value for an axis with a log scale. The space between the major tick marks determines the number of minor tick marks. If the MinorTickValues property is set to empty [], then no minor tick marks appear. Specify the tick mark locations by setting the MinorTickValues property.

Note

The MinorTick property for the ruler and the associated XMinorTick, YMinorTick, or ZMinorTick property for the parent axes always have the same value. Setting one also sets the other.

Example: ax.XAxis.MinorTick = 'on';

Minor tick mark locations, specified as a cell array of character vectors, a categorical array, or a string array indicating category names. The categories must be a subset of the categories in the Categories property and must appear in the same relative order that they appear in the Categories property.

If you assign values to this property, then MATLAB sets the MinorTickValuesMode property to 'manual'.

Data Types: categorical | string | cell

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

  • 'auto' — Use automatically calculated minor tick values.

  • 'manual' — Use minor tick values that you specify. To specify the values, set the MinorTickValues property.

Font

expand all

Font name, specified as a system supported font name or 'FixedWidth'. The default font depends on the specific system and locale. To use a fixed-width font that renders well, specify 'FixedWidth'. The actual fixed-width font used depends on the FixedWidthFontName property of the root object.

Note

Setting the FontName property for the parent axes sets the FontName property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.XAxis.FontName = 'Cambria';

Font size, specified as a scalar numeric value. The default font size depends on the specific operating system and locale.

Note

Setting the FontSize property for the parent axes sets the FontSize property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.XAxis.FontSize = 12;

Thickness of the text characters, 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.

Note

Setting the FontWeight property for the parent axes sets the FontWeight property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.XAxis.FontWeight = 'bold';

Character slant, specified as 'normal' or 'italic'. Not all fonts have both font styles. Therefore, the italic font can look the same as the normal font.

Note

Setting the FontAngle property for the parent axes sets the FontAngle property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.XAxis.FontAngle = 'italic';

Text smoothing, specified as one of these values:

  • 'on' — Enable text antialiasing to reduce the jagged appearance of text characters and make the text easier to read. In certain cases, smoothed text blends against the background color and can make the text appear blurry.

  • 'off' — Disable text antialiasing. Use this setting if the text seems blurry.

Note

Setting the FontSmoothing property for the parent axes sets the FontSmoothing property for the ruler to the same value. However, setting the ruler property does not set the axes property. To prevent the axes property value from overriding the ruler property value, set the axes value first, and then set the ruler value.

Example: ax.XAxis.FontSmoothing = 'off';

Parent/Child

expand all

Ruler parent, specified as an Axes object.

Note

Ruler objects are not listed in the Children property of the parent Axes object.

The ruler has no children. You cannot set this property.

Introduced in R2017a