Store date strings in array b at "moderate intervals" and set with set_xticklabels
hoge.py
import numpy as np
import matplotlib.pyplot as plt
ax = df.plot(kind='bar', color=['b','r','g'] , label ='hoge' ,alpha=0.3 )
#ax = plt.gca()
ln = len(df.index)
a = np.arange(ln)+1
b = []
for i in a-1:
b.append("") if i%5!=0 else b.append(str(df.index[i].strftime('%m/%d')))
#print(b)
ax.set_xticklabels(b,rotation =15)
X-axis notation is set by ax.xaxis.set_major_formatter etc.
hoge.py
ax = df.plot(kind='line', color=['b','r','g'] , label ='hoge' ,alpha=0.3 )
years = mdates.MonthLocator(interval=3)
months = mdates.MonthLocator()
daysFmt = mdates.DateFormatter("%m/%d")
ax.xaxis.set_major_locator(years)
ax.xaxis.set_minor_locator(months)
ax.xaxis.set_major_formatter( daysFmt )
Recommended Posts