I am trying to format the dates in a dataframe plot whose index is a time series.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
periods = 30
df = pd.DataFrame(np.random.randint(0, 20, size=periods),
columns=["Value"],
index=pd.date_range("20180306", periods=periods))
ax = df.plot(kind='bar')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %d %Y'))
plt.show()
The problem: Dates on the X-axis start at the epoch, so the chart shows "Jan 01 1970" as the first date.
Note that this problem goes away if I don't use a "bar" plot kind.
Any idea of how to fix this?