DurationRuler - Control axis with duration values - MATLAB (original) (raw)

DurationRuler Properties

Control axis with duration values

DurationRuler properties control the appearance and behavior of an _x_-axis, _y_-axis, or _z_-axis that shows duration 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, andZAxis properties of the Axes object.

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.

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 Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"red" "r" [1 0 0] "#FF0000" Sample of the color red
"green" "g" [0 1 0] "#00FF00" Sample of the color green
"blue" "b" [0 0 1] "#0000FF" Sample of the color blue
"cyan" "c" [0 1 1] "#00FFFF" Sample of the color cyan
"magenta" "m" [1 0 1] "#FF00FF" Sample of the color magenta
"yellow" "y" [1 1 0] "#FFFF00" Sample of the color yellow
"black" "k" [0 0 0] "#000000" Sample of the color black
"white" "w" [1 1 1] "#FFFFFF" Sample of the color white
"none" Not applicable Not applicable Not applicable No color

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

RGB Triplet Hexadecimal Color Code Appearance
[0 0.4470 0.7410] "#0072BD" Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue
[0.8500 0.3250 0.0980] "#D95319" Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange
[0.9290 0.6940 0.1250] "#EDB120" Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow
[0.4940 0.1840 0.5560] "#7E2F8E" Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple
[0.4660 0.6740 0.1880] "#77AC30" Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green
[0.3010 0.7450 0.9330] "#4DBEEE" Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue
[0.6350 0.0780 0.1840] "#A2142F" Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Note

The Color property for the ruler and the associatedXColor, YColor, orZColor 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

LabelHorizontalAlignment — Axis label horizontal alignment

'center' (default) | 'left' | 'right'

Axis label horizontal alignment, specified as one of the values from the table.

LabelHorizontalAlignment Value Description Appearance
'center' For a horizontal axis, the label is centered between the left and right edges of the plot box.For a vertical axis, the label is centered between the top and bottom edges of the plot box. Horizontal and a vertical axis labels that are centered.
'left' For a horizontal axis, the label is aligned with the left edge of the plot box.For a vertical axis, the label is aligned with the bottom edge of the plot box. Horizontal and a vertical axis labels that left-aligned.
'right' For a horizontal axis, the label is aligned with the right edge of the plot box.For a vertical axis, the label is aligned with the top edge of the plot box. Horizontal and a vertical axis labels that right-aligned.

Axis visibility, specified as 'on' or 'off', or as numeric or logical 1 (true) or0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent tofalse. 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.

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

Scale and Direction

expand all

Limits — Minimum and maximum axis limits

two-element vector of the form [min max]

Minimum and maximum axis limits, specified as a two-element vector of the form [min max], where min andmax are duration values. For example:

d = duration(1,40:45,0); y = rand(6,1); plot(d,y) ax = gca; ax.XAxis.Limits = [d(2) d(5)];

You can specify both limits, or specify one limit and let the ruler automatically calculate the other using an Inf or-Inf duration value, such asdays(Inf).

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

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

Note

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

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

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.

Scale — Scale of values along axis

'linear' (default)

Scale of values along axis, returned as 'linear'.DurationRuler objects do not support log scales.

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

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

TickValues — Tick mark locations along the axis

[] (default) | vector of duration values

Tick mark locations along the axis, specified as a vector of duration values. For example:

d = duration(1,40:45,0); y = rand(6,1); plot(d,y) ax = gca; ax.XAxis.TickValues = [d(1) d(3) d(5)];

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, orZTick property for the parent axes always have the same value. Setting one also sets the other.

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

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.

Exponent — Exponential notation common to all tick values

integer value

Exponential notation common to all tick values, specified as an integer value. The Exponent property applies only to tick labels that show a single unit of time, such as seconds, minutes, or hours. It does not apply to tick labels that show mixed units of time. When applicable, the ruler displays an exponent label showing the base and exponent value.

The base value is always 10. You can change the exponent value by setting the Exponent property. If the exponent value is0, then the exponent label is not displayed.

For example, this code changes the exponent value to 8.

x = hours((1:10)*1e10); plot(x,1:10) ax = gca; ax.XAxis.Exponent = 8;

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:

Tick mark labels, specified as a cell array of character vectors, string array, or categorical 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 theTickLabelInterpreter 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

Data Types: char | string | categorical

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

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.

TickLabelColor — Tick label color

[0.15 0.15 0.15] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ...

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

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 Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"red" "r" [1 0 0] "#FF0000" Sample of the color red
"green" "g" [0 1 0] "#00FF00" Sample of the color green
"blue" "b" [0 0 1] "#0000FF" Sample of the color blue
"cyan" "c" [0 1 1] "#00FFFF" Sample of the color cyan
"magenta" "m" [1 0 1] "#FF00FF" Sample of the color magenta
"yellow" "y" [1 1 0] "#FFFF00" Sample of the color yellow
"black" "k" [0 0 0] "#000000" Sample of the color black
"white" "w" [1 1 1] "#FFFFFF" Sample of the color white
"none" Not applicable Not applicable Not applicable No color

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

RGB Triplet Hexadecimal Color Code Appearance
[0 0.4470 0.7410] "#0072BD" Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue
[0.8500 0.3250 0.0980] "#D95319" Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange
[0.9290 0.6940 0.1250] "#EDB120" Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow
[0.4940 0.1840 0.5560] "#7E2F8E" Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple
[0.4660 0.6740 0.1880] "#77AC30" Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green
[0.3010 0.7450 0.9330] "#4DBEEE" Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue
[0.6350 0.0780 0.1840] "#A2142F" Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Note

Setting the ruler’s Color property also sets theTickLabelColor property to the same value. However, setting the TickLabelColor property does not change theColor property. To prevent the Color property value from overriding the TickLabelColor property value, set the Color property first, and then set theTickLabelColor property.

Tick label interpreter, specified as one of these values:

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.

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.

Modifiers remain in effect until the end of the text. Superscripts and subscripts are an exception because they modify only the next character or the characters within the curly braces. When you set the interpreter to 'tex', the supported modifiers are as follows.

Modifier Description Example
^{ } Superscript 'text^{superscript}'
_{ } Subscript 'text_{subscript}'
\bf Bold font '\bf text'
\it Italic font '\it text'
\sl Oblique font (usually the same as italic font) '\sl text'
\rm Normal font '\rm text'
\fontname{specifier} Font name — Replace_specifier_ with the name of a font family. You can use this in combination with other modifiers. '\fontname{Courier} text'
\fontsize{specifier} Font size —Replace_specifier_ with a numeric scalar value in point units. '\fontsize{15} text'
\color{specifier} Font color — Replace_specifier_ with one of these colors: red, green,yellow, magenta,blue, black,white, gray,darkGreen, orange, orlightBlue. '\color{magenta} text'
\color[rgb]{specifier} Custom font color — Replace_specifier_ with a three-element RGB triplet. '\color[rgb]{0,0.5,0.5} text'

This table lists the supported special characters for the'tex' interpreter.

Character Sequence Symbol Character Sequence Symbol Character Sequence Symbol
\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. TheFontName, FontWeight, andFontAngle 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 examples that use TeX and LaTeX, see Greek Letters and Special Characters in Chart Text. For more information about the LaTeX system, see The LaTeX Project website at https://www.latex-project.org/.

TickLabelFormat — Tick label format

character vector | string scalar

Tick label format, specified as a character vector or string scalar.

To display a duration as a single number that includes a fractional part (for example, 1.234 hours), specify one of the following formats.

Format Description
'y' Number of exact, fixed-length years. A fixed-length year is equal to 365.2425 days.
'd' Number of exact, fixed-length days. A fixed-length day is equal to 24 hours.
'h' Number of hours
'm' Number of minutes
's' Number of seconds

To display a duration in the form of a digital timer, specify one of these formats:

In addition, you can display up to nine fractional second digits by appending up to nine S characters. For example,'hh:mm:ss.SSS' displays the milliseconds of a duration value to three digits.

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:

Note

The TickLabelRotationMode property for the ruler and the corresponding mode property of the parent axes always have the same value. Setting one also sets the other.

Tick mark direction, specified as one of these values:

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.

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

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 'on' or 'off', or as numeric or logical 1 (true) or0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent tofalse. 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.

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

MinorTickValues — Minor tick mark locations

[] (default) | vector of increasing values

Minor tick mark locations, specified as a vector of increasing duration values.

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

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

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

Example: ax.XAxis.FontSize = 12;

Thickness of the text characters, specified as one of these values:

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 'on' or 'off', or as numeric or logical 1 (true) or0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent tofalse. 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.

Note

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

Callbacks

expand all

LimitsChangedFcn — Axis limits changed callback

'' (default) | function handle | cell array | character vector

Axis limits changed callback, specified as one of these values:

This callback executes after the axis limits have changed, either programmatically or using an interaction such as panning within the axes. It can also execute if MATLAB changes the axis limits to encompass the range of your data when you call a plotting function.

This callback function can access specific information about the axis limits. MATLAB passes this information in a LimitsChanged object as the second argument to your callback function. If you are developing an app in App Designer, the argument is calledevent. You can query the object properties using dot notation. For example, event.NewLimits returns the new axis limits. TheLimitsChanged object is not available to callback functions specified as character vectors.

The following table lists the properties of the LimitsChanged object.

Property Description
Source Ruler object that executes the callback
EventName 'LimitsChanged'
OldLimits Two-element vector containing the previous axis limits
NewLimits Two-element vector containing the new axis limits

For more information about writing callbacks in apps, see Callbacks in App Designer.

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.

Children — Ruler children

empty GraphicsPlaceholder array

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

Version History

Introduced in R2016b

expand all

R2022a: The FontSmoothing property will have no effect in a future release

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