Control axis with numeric values
NumericRuler properties control the
appearance and behavior of an x-axis, y-axis,
or z-axis that shows numeric 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
ZAxis properties of the
ax = gca; co = ax.XAxis.Color; ax.XAxis.Color = 'blue';
LabelHorizontalAlignment — Axis label horizontal alignment
'center' (default) |
Axis label horizontal alignment, specified as one of the values from the table.
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.
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.
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.
Scale and Direction
Tick Values and Labels
Exponent — Exponential notation common to all tick values
Exponential 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
Exponent property. For example, change the
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'. If the axis has a log scale, then the
Exponent property has no effect.
ExponentMode — Selection mode for
'auto' (default) |
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
TickLabelColor — Tick label color
[0.15 0.15 0.15] (default) | RGB triplet | hexadecimal color code |
'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.
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
F. The values are not case sensitive. Thus, the color codes
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|
|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|
Setting the ruler’s
Color property also sets the
TickLabelColor property to the same value. However, setting
TickLabelColor property does not change the
Color property. To prevent the
property value from overriding the
value, set the
Color property first, and then set the
TickLabelFormat — Tick label format and decimal precision
character vector | string
Tick label format and decimal precision, specified as a character vector or string. 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.
ax.XAxis.TickLabelFormat = '%g%%'; displays a
percent sign after all the tick labels.
This table lists some common formats.
|Common Format||Character Vector to Use||Examples of Resulting Format|
|Currency — Display dollar sign before values, use two decimal places, and use commas.||
$0.01 $1.00 $1,000.00
|Temperatures — Display degree symbol after values.||
0.01o 1o 1000o
|Percentages — Display percent sign after values.||
0.01% 1% 1000%
|Commas — Display commas in the thousandth place.||
0.01 1 1,000
If none of the formats mentioned in the table gives your desired format, then create a custom character vector or string with 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
Also, you can specify literal text at the beginning or end of the
format. To print a single quotation mark, use
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
Millionafter each value and use fixed-point notation with three decimal values.
|Identifier||Description||Example of Numeric Format|
|Display commas every three digits, such as
|Print the sign character (+) for positive values,
such as |
|Pad the field width with leading zeros instead of
spaces, such as |
|Left-justify, which pads the end of the value with
spaces instead of the beginning. For example, if the
field width is |
|Signed integer with base 10. The precision value indicates the number of significant digits.|
|Fixed-point notation. The precision value indicates the number of decimal places.|
|Exponential notation. The precision value indicates the number of decimal places.|
|The more compact version of |
LimitsChangedFcn — Axis limits changed callback
'' (default) | function handle | cell array | character vector
Axis limits changed callback, specified as one of these values:
A function handle.
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
This callback executes after the axis limits have changed, either programmatically or as a result of an interaction such as panning within the axes. It also executes if MATLAB changes the axis limits when you call a plotting function. Plotting functions can sometimes change the axis limits to encompass the range of your data.
This callback function can access specific information about the axis limits. MATLAB passes this information in a
LimitsChangedData object as the second argument to your callback function. If you are developing an app in App Designer, the argument is called
event. You can query the object properties using dot notation. For example,
event.NewLimits returns the new axis limits. The
LimitsChangedData object is not available to callback functions specified as character vectors.
The following table lists the properties of the
Ruler object that executes the callback
Two-element vector containing the previous axis limits
Two-element vector containing the new axis limits
For more information about writing callbacks in apps, see Write Callbacks in App Designer.
Children — Ruler children
The ruler has no children. You cannot set this property.