Control individual axis appearance and behavior
Numeric ruler properties control the appearance and behavior of the x-axis, y-axis, or z-axis. Each individual axis has its own numeric ruler object. By changing property values of the rulers, you can modify certain aspects of a specific axis.
Use dot notation to refer to a particular ruler and property.
Access the numeric ruler objects through the XAxis
, YAxis
,
and ZAxis
properties for the axes.
ax = gca; co = ax.XAxis.Color; ax.XAxis.Color = 'blue';
Color
— Color of axis line and labels'none'
Color of the axis line and labels, specified as an RGB triplet,
a character vector of a color name, or 'none'
.
If you set the color to 'none'
, then the axis is
invisible.
Example: ax.XAxis.Color = 'red';
Example: ax.YAxis.Color = [0.1 0.7 0.8];
An RGB triplet is a three-element row vector whose elements
specify the intensities of the red, green, and blue components of
the color. The intensities must be in the range [0,1]
;
for example, [0.4 0.6 0.7]
. This table lists the
long and short color name options and the equivalent RGB triplet values.
Long Name | Short Name | RGB Triplet |
---|---|---|
'yellow' | 'y' | [1 1 0] |
'magenta' | 'm' | [1 0 1] |
'cyan' | 'c' | [0 1 1] |
'red' | 'r' | [1 0 0] |
'green' | 'g' | [0 1 0] |
'blue' | 'b' | [0 0 1] |
'white' | 'w' | [1 1 1] |
'black' | 'k' | [0 0 0] |
Note:
The |
LineWidth
— Width of axis line and tick marks0.5
(default) | positive valueWidth 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 |
Label
— Axis labelAxis 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 numeric ruler object,
so it cannot be returned by |
Visible
— Axis visibility'on'
(default) | 'off'
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';
Limits
— Minimum and maximum axis limits[0 1]
(default) | two-element vector of the form [min max]
Minimum and maximum axis limits, specified as a two-element
vector of the form [min max]
.
If you assign a value to this property, then MATLAB® sets
the associated mode to 'manual'
.
Alternatively, set the limits using the xlim
, ylim
, and zlim
functions.
Note:
The |
Example: ax.XAxis.Limits = [-10 10];
LimitsMode
— Selection mode for Limits
property'auto'
(default) | 'manual'
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 |
Scale
— Scale of values along axis'linear'
(default) | 'log'
Scale of values along axis, specified as 'linear'
or 'log'
.
Note:
The |
Example: ax.XAxis.Scale = 'log';
Direction
— Direction of increasing values'normal'
(default) | 'reverse'
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 |
Example: ax.XAxis.Direction = 'reverse';
TickValues
— Tick mark locations along the axis[]
(default) | vector of increasing valuesTick mark locations along the axis, specified as a vector of increasing values.
Example: ax.XAxis.TickValues = [2 4 6 8 10];
Example: ax.XAxis.TickValues = 0:10:100;
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 |
TickValuesMode
— Selection mode for TickValues
property'auto'
(default) | 'manual'
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 |
Exponent
— Exponential notation common to all tick valuesExponential notation common to all tick values, specified as an integer value. The axis displays an exponent label showing the base and exponent value, for example:
The base value is always 10. However, you can change the exponent
value by setting the Exponent
property. For example,
change the exponent to 2.
ax = gca; ax.YAxis.Exponent = 2;
If the exponent value is 0
, then the exponent
label does not display.
If you assign a value to this property, then MATLAB sets
the ExponentMode
property to 'manual'
.
ExponentMode
— Selection mode for Exponent
property'auto'
(default) | 'manual'
Selection mode for the Exponent
property,
specified as one of these values:
'auto'
— Automatically select
the exponent value based on the axis limits.
'manual'
— Use an exponent
value that you specify. To specify the value, set the Exponent
property.
TickLabels
— Tick mark labels''
(default) | cell array of character vectors | string arrayTick mark labels, specified as a cell array of character vectors
or a string array. If you do not specify enough labels for all of
the tick values, then the labels repeat. The labels support TeX and
LaTeX markup. See the TickLabelInterpreter
property
for more information.
Example: ax.XAxis.TickLabels = {'January','February','March','April','May'}';
Example: ax.YAxis.TickLabels = {'\pi','2\pi','3\pi'}'
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:
The |
Data Types: char
| string
TickLabelsMode
— Selection mode for TickLabels
property'auto'
(default) | 'manual'
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 |
TickLabelInterpreter
— Interpretation of tick label characters'tex'
(default) | 'latex'
| 'none'
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 |
Example: ax.XAxis.TickLabelInterpreter = 'latex';
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 {}
.
Modifier | Description | Example |
---|---|---|
^{ } | Superscript | 'text^{superscript}' |
_{ } | Subscript | 'text_{subscript}' |
\bf | Bold font | '\bf text' |
\it | Italic font | '\it text' |
\sl | Oblique font (rarely available) | '\sl text' |
\rm | Normal 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 Sequence | Symbol | Character Sequence | Symbol | Character Sequence | Symbol |
---|---|---|---|---|---|
| α |
| υ |
| ~ |
| ∠ |
| Φ |
| ≤ |
|
|
| χ |
| ∞ |
| β |
| ψ |
| ♣ |
| γ |
| ω |
| ♦ |
| δ |
| Γ |
| ♥ |
| ɛ |
| Δ |
| ♠ |
| ζ |
| Θ |
| ↔ |
| η |
| Λ |
| ← |
| Θ |
| Ξ |
| ⇐ |
| ϑ |
| Π |
| ↑ |
| ι |
| Σ |
| → |
| κ |
| ϒ |
| ⇒ |
| λ |
| Φ |
| ↓ |
| µ |
| Ψ |
| º |
| ν |
| Ω |
| ± |
| ξ |
| ∀ |
| ≥ |
| π |
| ∃ |
| ∝ |
| ρ |
| ∍ |
| ∂ |
| σ |
| ≅ |
| • |
| ς |
| ≈ |
| ÷ |
| τ |
| ℜ |
| ≠ |
| ≡ |
| ⊕ |
| ℵ |
| ℑ |
| ∪ |
| ℘ |
| ⊗ |
| ⊆ |
| ∅ |
| ∩ |
| ∈ |
| ⊇ |
| ⊃ |
| ⌈ |
| ⊂ |
| ∫ |
| · |
| ο |
| ⌋ |
| ¬ |
| ∇ |
| ⌊ |
| x |
| ... |
| ⊥ |
| √ |
| ´ |
| ∧ |
| ϖ |
| ∅ |
| ⌉ |
| 〉 |
| | |
| ∨ |
| 〈 |
| © |
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, this is reduced by about 10 characters
per line.
For more information about the LaTeX system, see The LaTeX Project website at http://www.latex-project.org/.
TickLabelFormat
— Tick label format and decimal precisionTick label format and decimal precision, specified as a character vector of numeric format. For example, you can display the tick labels in a currency format, control the number of decimals that appear in each label, or add text after all the labels.
Example: ax.XAxis.TickLabelFormat = '%g%%';
displays
a percent sign after all the tick labels.
This table lists some common formats and the associated character vector.
Common Format | Character Vector to Use | Examples of Resulting Format |
---|---|---|
Currency — Display dollar sign before values, use two decimal places, and use commas. | '$%,.2f' | $0.01 $1.00 $1,000.00 |
Temperatures — Display degree symbol after values. | '%g\\circ' | 0.01o 1o 1000o |
Percentages — Display percent sign after values. | '%g%%' | 0.01% 1% 1000% |
Commas — Display commas in the thousandth place. | '%,g' | 0.01 1 1,000 |
Alternatively, specify the tick label format using the xtickformat
, ytickformat
,
and ztickformat
functions.
If none of the formats mentioned in the table gives your desired format, then create a custom character vector of identifiers.
Identifiers are optional, except the percent sign and conversion character. Construct the format in this order:
One or more flags — Options such as adding a plus sign before positive values. For a full list of options, see the table of Optional Flags.
Field width — Minimum number of characters to print in the tick label. Specify the field width as an integer value. If the number of significant digits in the tick value is smaller than the field width, then the label is padded with spaces.
Precision — Number of digits to the right of the decimal point or the number of significant digits, depending on the conversion character. Specify the precision as an integer value.
Conversion character — Value type. For a full
list of options, see the table of Conversion Characters. If you specify a conversion that does
not fit the data, MATLAB overrides the specified conversion and
uses %e
.
Also, you can specify literal text at the beginning or end of
the format. To print a single quotation mark, use ''
.
To print a percent character, use %%
.
'$%.2f'
— Display a dollar
sign before each value and use fixed-point notation with two decimal
values.
'%.3f Million'
— Display Million
after
each value and use fixed-point notation with three decimal values.
Optional Flags
Identifier | Description | Example of Numeric Format |
---|---|---|
, | Display commas every three digits, such as '1,000' . | '%,4.4g' |
+ | Print the sign character (+) for positive values, such as '+100' . | '%+4.4g' |
0 | Pad the field width with leading zeros instead of spaces, such
as '0100' . | '%04.4g' |
– | Left-justify, which pads the end of the value with spaces instead
of the beginning. For example, if the field width is 4 ,
then this flag formats the label as '100 ' instead
of ' 100' . | '%-4.4g' |
# | For the | '%#4.4g' |
Conversion Characters
Identifier | Description | Example |
---|---|---|
d or i | Signed integer with base 10. The precision value indicates the number of significant digits. | '%.4d' displays π as 0003 . |
f | Fixed-point notation. The precision value indicates the number of decimal places. | '%.4f' displays π as 3.1416 . |
e | Exponential notation. The precision value indicates the number of decimal places. | '%.4e' displays π as 3.1416x100 . |
g | The more compact version of e or f ,
with no trailing zeros. The precision value indicates the maximum
number of decimal places. | '%.4g' displays π as 3.1416 . |
TickLabelRotation
— Rotation of tick labelsRotation 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 |
Example: ax.XAxis.TickLabelRotation = 45;
Example: ax.YAxis.TickLabelRotation = -45;
TickDirection
— Tick mark direction'in'
(default) | 'out'
| 'both'
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 |
Example: ax.YAxis.TickDirection = 'out';
TickDirectionMode
— Selection mode for TickDirection
property'auto'
(default) | 'manual'
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.
TickLength
— Tick mark lengthTick 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 |
Example: ax.YAxis.TickLength = [0.02 0.035];
MinorTick
— Minor tick mark display'off'
(default) | 'on'
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 |
Example: ax.XAxis.MinorTick = 'on';
MinorTickValues
— Minor tick mark locations[]
(default) | vector of increasing valuesMinor tick mark locations, specified as a vector of increasing values.
Example: ax.XAxis.MinorTickValues = [0 0.5 1 1.5 2 2.5];
Example: ax.YAxis.MinorTickValues = 0:5:100;
If you assign values to this property, then MATLAB sets
the MinorTickValuesMode
property to 'manual'
.
MinorTickValuesMode
— Selection mode for MinorTickValues
property'auto'
(default) | 'manual'
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.
FontName
— Font name'FixedWidth'
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 |
Example: ax.XAxis.FontName = 'Cambria';
FontSize
— Font size10
(default) | scalar numeric valueFont size, specified as a scalar numeric value.
Note:
Setting the |
Example: ax.XAxis.FontSize = 12;
FontWeight
— Thickness of text characters'normal'
(default) | 'bold'
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 |
Example: ax.XAxis.FontWeight = 'bold';
FontAngle
— Text character slant'normal'
(default) | 'italic'
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 |
Example: ax.XAxis.FontAngle = 'italic';
FontSmoothing
— Text antialiasing'on'
(default) | 'off'
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 |
Example: ax.XAxis.FontSmoothing = 'off';
Parent
— Parent of numeric rulerParent of the numeric ruler, specified as an axes object.
Note:
Ruler objects are not listed in the |
Children
— Children of numeric rulerGraphicsPlaceholder
arrayThe numeric ruler has no children. You cannot set this property.