from matplotlib.widgets import LassoSelector from matplotlib.path import Path
classSelectFromCollection(object): """Select indices from a matplotlib collection using `LassoSelector`. Selected indices are saved in the `ind` attribute. This tool fades out the points that are not part of the selection (i.e., reduces their alpha values). If your collection has alpha < 1, this tool will permanently alter the alpha values. Note that this tool selects collection objects based on their *origins* (i.e., `offsets`). Parameters ---------- ax : :class:`~matplotlib.axes.Axes` Axes to interact with. collection : :class:`matplotlib.collections.Collection` subclass Collection you want to select from. alpha_other : 0 <= float <= 1 To highlight a selection, this tool sets all selected points to an alpha value of 1 and non-selected points to `alpha_other`. """
# Ensure that we have separate colors for each object self.fc = collection.get_facecolors() iflen(self.fc) == 0: raise ValueError('Collection must have a facecolor') eliflen(self.fc) == 1: self.fc = np.tile(self.fc, (self.Npts, 1))