datetick
Date formatted tick labels
Syntax
Description
Note
It is often more convenient to plot datetime
values using the desired
plotting function. Then you can format the tick
labels using the xtickformat
and ytickformat
functions.
datetick
is useful when
plotting numeric values that are serial date
numbers.
datetick(
labels the tick lines of the axis specified by
tickaxis
)tickaxis
using dates, replacing
the default numeric labels.
datetick
selects a label format
based on the minimum and maximum limits of the
specified axis. The axis data values should be
serial date numbers, as returned by the
datenum
function.
datetick(
formats
the labels according to tickaxis
,dateFormat
)dateFormat
.
datetick(___,'keeplimits')
changes
the tick labels to date-based labels while preserving the axis limits.
Append 'keeplimits'
to any of the previous syntaxes.
datetick(___,'keepticks')
changes the tick labels to date-based labels while
preserving their locations. Append
'keepticks'
to any of the
previous syntaxes.
datetick(axes_handle,___)
labels the tick lines of an axis on the axes
specified by axes_handle
. The
axes_handle
argument can
precede any of the input argument combinations in
the previous syntaxes.
Examples
Input Arguments
Tips
To change the tick spacing and locations, set the appropriate axes property (that is,
XTick
,YTick
, orZTick
) before callingdatetick
.Calling
datetick
sets theTickMode
of the specified axis to'manual'
. This means that after zooming, panning or otherwise changing axis limits, you should calldatetick
again to update the ticks and labels.The best way to work with dates and times in MATLAB is to use
datetime
values, which offer more features than serial date numbers. Plotdatetime
values using theplot
function. Use theDatetimeTickFormat
name-value pair argument to modify the format of the axis tick labels.
Algorithms
datetick
calls the datestr
function
to convert date numbers to text.
Version History
Introduced before R2006a