razhangwei
3/3/2015 - 8:03 PM

Customize the styles of x-axis with dates.

Customize the styles of x-axis with dates.

import matplotlib.dates as mdates

plot.hist(mdates.date2num(dts), 100)		# plot the histogram

ax = plt.gca()
ax.xaxis.set_major_locator(mdates.AutoDateLocator())		  	# set the major ticker, use AutoDateLocator
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))	# show the label			
ax.xaxis.set_minor_locator(mdates.DayLocator())				      # set the minor ticker, use DayLocator