The other day I needed to make a plot with dates as the x-axis. Matplotlib supports this, but the examples I was finding weren’t quite as complete as I would have liked. So here’s what I put together as an example.
First, imports. Make sure to get the matplotlib.dates module.
import matplotlib.dates as mdates import matplotlib.pyplot as plt from datetime import datetime
We’ll want the date values in the form of datetime objects.