datetick
Date formatted tick labels
Syntax
Description
Note
It is often more convenient to plotdatetime
values using the desired plotting function. Then you can format the tick labels using thextickformat
andytickformat
functions.datetick
is useful when plotting numeric values that are serial date numbers.
datetick(
labels the tick lines of the axis specified bytickaxis
)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 thedatenum
function.
datetick(
formats the labels according totickaxis
,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 byaxes_handle
. Theaxes_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 thedatestr
function to convert date numbers to text.