ztickformat
Specifyz-axis tick label format
Syntax
ztickformat(fmt)
ztickformat(datefmt)
ztickformat(durationfmt)
ztickformat(ax,___)
zfmt = ztickformat
zfmt = ztickformat(ax)
Description
ztickformat(
sets the format for numericz-axis tick labels. For example, specifyfmt
)fmt
as'usd'
to display the labels in U.S. dollars.
ztickformat(
sets the format for labels that show dates or times. For example, specifydatefmt
)datefmt
as'MM-dd-yy'
to display dates such as04-19-16
. This option applies only to az-axis with datetime values.
ztickformat(
sets the format for labels that show durations. For example, specifydurationfmt
)durationfmt
as'm'
to display the durations in minutes. This option applies only to az-axis with duration values.
returns the format style used forz-axis tick labels of the current axes. Depending on the type of labels along thez-axis,zfmt
= ztickformatzfmt
is a character vector of a numeric format, date format, or duration format.
returns the format style used for the axes specified byzfmt
= ztickformat(ax
)ax
instead of the current axes.
Examples
Displayz-Axis Tick Labels in Dollars
Create a 3-D stem chart of random data. Display the tick labels along thez-axis in US dollars.
z = 10*rand(5); stem3(z) ztickformat('usd')
Query the tick label format. MATLAB® returns the format as a character vector containing the formatting operators.
fmt = ztickformat
fmt = '$%,.2f'
Display the tick labels with no decimal values by tweaking the numeric format to use a precision value of 0 instead of 2.
ztickformat('$%,.0f')
Display Text After Eachz-Axis Tick Label
Create a 3-D line chart. Display the tick labels along thez-axis with the text "cm" after each value.
t = 0:pi/10:10*pi; st = sin(t); ct = cos(t); plot3(st,ct,t) gridonztickformat('%g cm')
Control Number of Decimal Places forz-Axis Tick Labels
Create a 3-D scatter plot of random data. Display thez-axis tick labels with two decimal places. Control the decimal places by passingztickformat
a character vector of a numeric format that uses fixed-point notation for the conversion character and a precision value of 2.
x = rand(50,1); y = rand(50,1); z = rand(50,1); scatter3(x,y,z) ztickformat('%.2f')
Specifyz-Axis Tick Label Format for Specific Axes
Create a figure with two subplots and return the axes objects asax1
andax2
. Specify thez-axis tick label format for the left subplot by specifyingax1
as the first input argument toztickformat
. Display the tick labels in US dollars.
ax1 = subplot(1,2,1); stem3(4*rand(5)) ztickformat(ax1,'usd') ax2 = subplot(1,2,2); stem3(4*rand(5))
Input Arguments
fmt
—为mat for numeric tick labels
'%g'
(default) |character vector|string
为mat for numeric tick labels, specified as a character vector or string. You can specify one of the formats listed in this table. Alternatively, you can specify a custom format.
Predefined Format | Description |
---|---|
'usd' |
U.S. dollars. This option is equivalent using |
'eur' |
Euro. This option is equivalent to using |
'gbp' |
英镑。相当于使用这个选项 |
'jpy' |
Japanese yen. This option is equivalent to using |
'degrees' |
Display degree symbol after values. This option is equivalent to using |
'percentage' |
Display percent sign after values. This option is equivalent to using |
'auto' |
Default format of |
Example:ztickformat('usd')
Custom Numeric Format
You can specify a custom numeric format by creating a character vector or string containing 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 ofOptional 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 ofConversion Characters. If you specify a conversion that does not fit the data, then 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%%
.
Example:ztickformat('%.2f')
displays the values using fixed-point notation with two decimal places.
Example:ztickformat('$%.2f')
displays a dollar sign before each value.
Example:ztickformat('%.2f million')
displaysmillion
after each value.
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 is4 , then this flag formats the label as'100 ' instead of' 100' . |
'%-4.4g' |
# |
为the |
'%#4.4g' |
Conversion Characters
Identifier | Description | Example |
---|---|---|
d ori |
Signed integer with base 10. The precision value indicates the number of significant digits. | '%.4d' displays π as0003 . |
f |
Fixed-point notation. The precision value indicates the number of decimal places. | '%.4f' displays π as3.1416 . |
e |
Exponential notation. The precision value indicates the number of decimal places. | '%.4e' displays π as3.1416x100 . |
g |
The more compact version ofe orf , with no trailing zeros. The precision value indicates the maximum number of decimal places. |
'%.4g' displays π as3.1416 . |
datefmt
—为mat for dates and times
'auto'
|character vector|string
为mat for dates and times, specified as'auto'
, a character vector, or a string. The default format is based on the data.
Example:ztickformat(“yyyy-MM-dd”)
displays a date and time such as2016-04-19
.
Example:ztickformat('eeee, MMMM d, yyyy HH:mm:ss')
displays a date and time such asSaturday, April 19, 2016 21:41:06
.
Example:ztickformat('MMMM d, yyyy HH:mm:ss Z')
displays a date and time such asApril 19, 2016 21:41:06 -0400
.
The display format tables show the letter identifiers that you can use to construct the format. To separate the fields, you can include nonletter characters such as a hyphen, space, colon, or any non-ASCII characters. The identifiers correspond to the Unicode®Locale Data Markup Language (LDML) standard for dates.
Date and Time Formats
Use these identifiers to specify the display formats of the date and time fields.
Letter Identifier | Description | Display |
---|---|---|
G |
Era | CE |
y |
Year, with no leading zeros. See the Note that follows this table. | 2014 |
yy |
Year, using last two digits. See the Note that follows this table. | 14 |
yyy ,yyyy ... |
Year, using at least the number of digits specified by the number of instances of'y' |
为the year 2014,'yyy' displays2014 , while'yyyyy' displays02014 . |
u ,uu , ... |
ISO year. A single number designating the year. An ISO year value assigns positive values to CE years and negative values to BCE years, with 1 BCE being year 0. | 2014 |
Q |
Quarter, using one digit | 2 |
QQ |
Quarter, using two digits | 02 |
QQQ |
Quarter, abbreviated | Q2 |
QQQQ |
Quarter, full name | 2nd quarter |
M |
Month, numerical using one or two digits | 4 |
MM |
Month, numerical using two digits | 04 |
MMM |
Month, abbreviated name | Apr |
MMMM |
Month, full name | April |
MMMMM |
Month, capitalized first letter | A |
W |
Week of the month | 1 |
d |
Day of the month, using one or two digits | 5 |
dd |
Day of the month using two digits | 05 |
D |
Day of the year, using one, two or three digits | 95 |
DD |
Day of the year using two digits | 95 |
DDD |
Day of the year using three digits | 095 |
e |
Day of the week, numerical using one or two digits. | 7 , where Sunday is the first day of the week. |
ee |
Day of the week, numerical using two digits | 07 |
eee |
Day, abbreviated name | Sat |
eeee |
Day, full name | Saturday |
eeeee |
Day, capitalized first letter | S |
a |
Day period (AM or PM) | PM |
h |
Hour, 12-hour clock notation using one or two digits | 9 |
hh |
Hour, 12-hour clock notation using two digits | 09 |
H |
Hour, 24-hour clock notation using one or two digits | 21 |
HH |
小时,24小时时钟使用两个数字符号 | 21 |
m |
Minute, using one or two digits | 41 |
mm |
Minute, using two digits | 41 |
s |
Second, using one or two digits | 6 |
ss |
Second, using two digits | 06 |
S ,SS , ...,SSSSSSSSS |
Fractional second, using the number of digits specified by the number of instances of'S' (up to 9 digits). |
'SSS' truncates 6.12345 seconds to123 . |
Some tips and considerations:
Use one or more
u
characters instead ofy
characters to represent the year when working with year numbers near zero.Datetime values later than 144683 years CE or before 140743 BCE display only the year numbers, regardless of the specified format value.
Time Zone Offset Formats
Use these identifiers to specify the display format of the time zone offset. A time zone offset is the amount of time that a specific date and time is offset from UTC. A time zone offset is different from a time zone in that it comprises rules that determine the offsets for specific times of the year. Include a time zone offset identifier when you want to ensure that the time components are displayed unambiguously.
Letter Identifier | Description | Display |
---|---|---|
z |
Abbreviated name of the time zone offset. If this value is not available, then the time zone offset uses the short UTC format, such asUTC-4 . |
EDT |
Z |
ISO 8601 basic format with hours, minutes, and optional seconds fields. | -0400 |
ZZZZ |
Long UTC format. | UTC-04:00 |
ZZZZZ |
ISO 8601 extended format with hours, minutes, and optional seconds fields. A time offset of zero is displayed as the ISO 8601 UTC indicator “Z”. | -04:00 |
x orX |
ISO 8601 basic format with hours field and optional minutes field. If you specifyX , a time offset of zero is displayed as the ISO 8601 UTC indicator “Z”. |
-04 |
xx orXX |
ISO 8601 basic format with hours and minutes fields. If you specifyXX , a time offset of zero is displayed as the ISO 8601 UTC indicator “Z”. |
-0400 |
xxx orXXX |
ISO 8601 extended format with hours and minutes fields. If you specifyXXX , a time offset of zero is displayed as the ISO 8601 UTC indicator “Z”. |
-04:00 |
xxxx orXXXX |
ISO 8601 basic format with hours, minutes, and optional seconds fields. If you specifyXXXX , a time offset of zero is displayed as the ISO 8601 UTC indicator “Z”. |
-0400 |
xxxxx orXXXXX |
ISO 8601 extended format with hours, minutes, and optional seconds fields. If you specifyXXXXX , a time offset of zero is displayed as the ISO 8601 UTC indicator “Z”. |
-04:00 |
durationfmt
—为mat for duration values
character vector|string
为mat for duration values, specified as a character vector or string.
To display a duration as a single number that includes a fractional part (for example, 1.234 hours), specify one of the following formats.
为mat | 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:
'dd:hh:mm:ss'
'hh:mm:ss'
'mm:ss'
'hh:mm'
In addition, you can display up to nine fractional second digits by appending up to nineS
characters. For example,'hh:mm:ss.SSS'
displays the milliseconds of a duration value to three digits.
ax
—Target axes
current axes(default) |singleAxes
对象|vector ofAxes
对象s
Target axes, specified as a singleAxes
对象or a vector ofAxes
对象s. If you do not specify the axes, thenztickformat
uses the current axes.
Algorithms
Theztickformat
function sets and queries theTickLabelFormat
property of the ruler object associated with thez-axis.
See Also
Functions
Properties
Introduced in R2016b
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.
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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
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
- United Kingdom(English)