datetick

Formats axis tick labels as dates.

Category: Graphics > Formatting and Annotation

Syntax

datetick

Labels the x-axis ticks as dates.

datetick(tickaxis)

Chooses the axis: 'x', 'y' or 'z'.

datetick(tickaxis, dateform)

Uses a date format given as a number or a pattern such as 'dd-mmm'.

Description

The data on the chosen axis must be serial date numbers, as returned by datenum. The function replaces the numeric tick labels by formatted dates but keeps the tick positions. Newer code often uses datetime values, which are formatted automatically.

Input arguments

tickaxis
'x' (default), 'y' or 'z'.
dateform
Date format number or pattern.

Example

Days of January

t = datenum(2024, 1, 1:30);
plot(t, 1:30)
datetick('x', 'dd-mmm')

In the app, the figure is drawn below the code.

See also

datenum datestr datetime xticklabels