Sooner or later, we all have had the need to plot some information over time, be it for the bank account balance each month, the total web site accesses for each day of the year, or one of many other reasons.
Matplotlib has a plotting function ad hoc for dates,
plot_date() that considers data on X, Y, or both axes, as dates, labeling the axis accordingly.
As usual, we now present an example, and we will discuss it later:
In : import matplotlib as mpl In : import matplotlib.pyplot as plt In : import numpy as np In : import datetime as dt In : dates = [dt.datetime.today() + dt.timedelta(days=i) \ ...: for i in range(10)] In : values = np.random.rand(len(dates)) In : plt.plot_date(mpl.dates.date2num(dates), values, ...