Date formatted tick labels
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.
To change the tick spacing and locations, set the appropriate axes property (that is,
XTick
, YTick
, or ZTick
) before calling
datetick
.
Calling datetick
sets the TickMode
of
the specified axis to 'manual'
. This means that
after zooming, panning or otherwise changing axis limits, you should
call datetick
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. Plot datetime
values
using the plot
function. Use the DatetimeTickFormat
name-value
pair argument to modify the format of the axis tick labels.
datetick
calls the datestr
function
to convert date numbers to text.