import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
import numpy as np
import datetime
class TimeSelector(SpanSelector):
    """
    SpanSelector that is only activated by the left mouse button
    """
    def ignore(self,event):
        if event.button == 2 or event.button == 3: return True

def onselect(xmin,xmax):
    print xmin,xmax
    
fig = plt.figure()
ax = fig.add_subplot(111)
span = TimeSelector(ax, onselect, 'horizontal', useblit=True, rectprops=dict(alpha=0.5, facecolor='yellow') )

y = np.random.rand(100,1)
start = datetime.datetime(2010,7,15,0,0)
x = []
for i in range(len(y)):
    x.append(start + datetime.timedelta(hours=i))
   
ax.plot_date(x,y,'b-')
plt.show()