I am trying to modify a plot within a mouseevent definition in matplotlib. My final endpoint is to be able to get the user to drag a greyed out area marking the starting and ending x coordinates, from which I can determine the local maxima/minima. This is where I am currently. While the first avxspan shows up in the plot, the second one doesnt. I know the mouseevent is triggered since the x,y coords are printed on console. Can someone tell me why this wouldnt work? Much appreciated.
fig=plt.figure()
plt.figure(fig.number)
plt.plot(data)
ax=plt.gca()
plt.figtext(0.25,0.92, "Calculate")
plt.figtext(0.66,0.92, "Clear")
ax.axvspan(1, 100, facecolor='0.5', alpha=0.5)
def start(event):
global ax
ax.axvspan(100, 200, facecolor='0.5', alpha=0.5)
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
cid = fig.canvas.mpl_connect('button_press_event', start)
plt.show()
fig.canvas.mpl_disconnect(cid)