Matplotlib datetime examples

Matplotlib can make many types of plots with a time axis. However, sometimes it takes an additional command or two to make the date/time axis work right in Matplotlib.

As seen in, for imshow() datetime64 extent, you need to do something like:

import matplotlib.dates as mdates

# whatever your time vector is
t = np.arange('2010-05-04T12:05','2010-05-04T12:06', dtype='datetime64[s]').astype(datetime)

mt = mdates.date2num((t[0],t[-1]))

ax.imshow(im, extent=[mt[0],mt[1], y[0],y[-1]], aspect='auto')

In most Matplotlib plotting functions numpy.datetime64 is a first-class citizen, but not yet for imshow() perhaps due to the limits-oriented nature of imshow(). We use pcolormesh() instead of imshow() for datetime-oriented raster data.