MATLAB Function Reference |
Syntax
datetick(tickaxis)
datetick(tickaxis,dateform
)
datetick(...,'keeplimits')
datetick(...,'keepticks')
datetick(axes_handle,...)
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,
formats the labels according to the integer dateform
)
dateform
(see table). To produce correct results, the data for the specified axis must be serial date numbers (as produced by datenum
).
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:
t = (1900:10:1990)'; %Time interval
p = [75.995 91.972 105.711 123.203 131.669 ... 150.697 179.323 203.212 226.505 249.633]'; %Population
plot(datenum(t,1,1),p) %Convert years to date numbers and plot
grid on datetick('x',11)% Replace x-axis ticks with 2-digit year labels
See Also
The axes properties XTick
, YTick
, and ZTick
Annotating Plots for related functions
datestr | datevec |
© 1994-2005 The MathWorks, Inc.