MATLAB Function Reference Previous page   Next Page
datetick

Label tick lines using dates

Syntax

Description

datetick(tickaxis) labels the tick lines of an axis using dates, replacing the default numeric labels. tickaxis is the string 'x', 'y', or 'z'. The default is 'x'. datetick selects a label format based on the minimum and maximum limits of the specified axis.

datetick(tickaxis,dateform) formats the labels according to the integer dateform (see table). To produce correct results, the data for the specified axis must be serial date numbers (as produced by datenum).

dateform (number)
dateform (string)
Example
0
'dd-mmm-yyyy HH:MM:SS'
01-Mar-2000 15:45:17
1
'dd-mmm-yyyy'
01-Mar-2000
2
'mm/dd/yy'
03/01/00
3
'mmm'
Mar
4
'm'
M
5
'mm'
03
6
'mm/dd'
03/01
7
'dd'
01
8
'ddd'
Wed
9
'd'
W
10
'yyyy'
2000
11
'yy'
00
12
'mmmyy'
Mar00
13
'HH:MM:SS'
15:45:17
14
'HH:MM:SS PM'
3:45:17 PM
15
'HH:MM'
15:45
16
'HH:MM PM'
3:45 PM
17
'QQ-YY'
Q1-01
18
'QQ'
Q1
19
'dd/mm'
01/03
20
'dd/mm/yy'
01/03/00
21
'mmm.dd.yyyy HH:MM:SS'
Mar.01,2000 15:45:17
22
'mmm.dd.yyyy'
Mar.01.2000
23
'mm/dd/yyyy'
03/01/2000
24
'dd/mm/yyyy'
01/03/2000
25
'yy/mm/dd'
00/03/01
26
'yyyy/mm/dd'
2000/03/01
27
'QQ-YYYY'
Q1-2001
28
'mmmyyyy'
Mar2000

datetick(...,'keeplimits') changes the tick labels to date-based labels while preserving the axis limits.

datetick(...,'keepticks') changes the tick labels to date-based labels without changing their locations.

You can use both keeplimits and keepticks in the same call to datetick.

datetick(axes_handle,...) uses the axes specified by the handle ax instead of the current axes.

Remarks

datetick calls datestr to convert date numbers to date strings.

To change the tick spacing and locations, set the appropriate axes property (i.e., XTick, YTick, or ZTick) before calling datetick.

Example

Consider graphing population data based on the 1990 U.S. census:

See Also

The axes properties XTick, YTick, and ZTick

datenum, datestr

Annotating Plots for related functions


Previous page  datestr datevec Next page

© 1994-2005 The MathWorks, Inc.