self.y0 = event.ydata

def on_release(self, event):
    print('release')
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
a = Annotate()
plt.show()
Matplotlib: draw a selection area in the shape of a rectangle with the mouse