Matlab pcolor datetime plots

Matlab datetime works much like Python datetime, and is generally recommended. Matlab plotting functions generally support “datetime” class. It is sometimes necessary to manipulate Matlab plots involving datetime for the desired result.

dt = datetime(2019, 12, 1):datetime(2020, 3, 1);

dat = rand([100, length(dt)]);
y = 1:size(dat, 1);

pcolor(dt, y, dat)

If the plot doesn’t have the desired datetime axis formatting, try datetick.

datetick('x', 'yyyy-mm-dd', 'keepticks')

Generate vector of datetime. Python matplotlib supports datetime.datetime and numpy.datetime64 in most plot functions.