How to change the datatip format in a plot with a datetime axis?

Hi. I'm plotting numeric values vs a datetime vector but, I want to change the datatip format of the datetime vector. I'd like to change it from "MMM dd, yyyy" to "dd-MM-yyyy". Is it possible?
Thanks.

 Accepted Answer

Specify the format by setting the Format property of the data tip template.
% Create plot
dt = datetime('today')+days(1:5);
data = rand(size(dt));
h = plot(dt, data);
% Set datatip template format for the x-variable
dtt = h.DataTipTemplate;
dtt.DataTipRows(1).Format = 'dd-MM-yyyy'; % (1) for 'x'
% Create a datatip for demo purposes
datatip(h,dt(3),data(3));

More Answers (0)

Categories

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!