Matplotlib - Advanced event picking

I am currently playing around with a small interactive matplotlib script that I want to use to mark different events within an image.

In order to make it more flexible I want to create it in a way that I can pick events either per mouse-click (and somewhat vary the brush-size of my curser, i.e. the number of adjacent points that are co-selected) or within a polygon.

So far, I managed to implement changing the brush-size for events that I select with left-click and drawing a polyline into my plot.

from matplotlib import pyplot as plt
%matplotlib notebook


points = []
bs = 5 #brush size


def onclick(event):
    global points
    points.append([event.xdata, event.ydata])

    if bs == 1:
        ax.plot(event.xdata+bs, event.ydata+bs,'b+')
    elif bs == 3:
        ax.plot(event.xdata, event.ydata+1,'b+')
        ax.plot(event.xdata, event.ydata-1,'b+')
        ax.plot(event.xdata+1, event.ydata,'b+')
    ax.plot(event.xdata-1, event.ydata,'b+')
    ax.plot(event.xdata, event.ydata,'b+')
    elif bs == 5:
        ax.plot(event.xdata, event.ydata+1,'b+')
        ax.plot(event.xdata, event.ydata-1,'b+')
        ax.plot(event.xdata+1, event.ydata,'b+')
        ax.plot(event.xdata-1, event.ydata,'b+')
        ax.plot(event.xdata, event.ydata,'b+')
        ax.plot(event.xdata, event.ydata+2,'b+')
        ax.plot(event.xdata, event.ydata-2,'b+')
        ax.plot(event.xdata+2, event.ydata,'b+')
        ax.plot(event.xdata-2, event.ydata,'b+')
        ax.plot(event.xdata+1, event.ydata+1,'b+')
        ax.plot(event.xdata-1, event.ydata-1,'b+')
        ax.plot(event.xdata+1, event.ydata-1,'b+')
        ax.plot(event.xdata-1, event.ydata+1,'b+')



    plt.draw()


class LineBuilder:
    def __init__(self, line):

        self.line = line
        self.xs = list(line.get_xdata())
        self.ys = list(line.get_ydata())
        self.cid = line.figure.canvas.mpl_connect('button_press_event',self)
        #self.cid = line.figure.canvas.mpl_connect('key_press_event', self)


    def __call__(self, event):
        #print('click', event)
        if event.inaxes!=self.line.axes: return
        self.xs.append(event.xdata)
        self.ys.append(event.ydata)
        self.line.set_data(self.xs, self.ys)
        self.line.figure.canvas.draw()
        return self



fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title(('click to build line segments. brush size %d; press button to paint') % bs)
line, = ax.plot(points, 'r+--')
linebuilder = LineBuilder(line)

plt.gcf().canvas.mpl_connect('key_press_event', onclick)

ax.set_xlim((0, 10))
ax.set_ylim((0, 10))
plt.show()
  1. Is there a way in matplotlib to switch between the lists where the X/Y coordinates of the individual picks are stored by pressing a hotkey?
  2. Does matlablib support autopicking of events which lie within my polyline?
  3. Can I delete picked events either by something equivalent to CTRL-Z or an eraser?

Many thanks in advance!