Plot pandas dates in matplotlib

If you use a list containing the column name(s) instead of a string, data.set_index will work

The following should show the dates on x-axis:

#! /usr/bin/env python
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_fwf('myfile.log',header=None,names=['time','amount'],widths=[27,5])
data.time = pd.to_datetime(data['time'], format="%Y-%m-%d %H:%M:%S.%f")

plt.plot(data.index, data.amount)

Leave a Comment