class MplPathROI(MplPolygonalROI): def roi_factory(self): return Path() def _setup_patch(self): self._patch = None def _sync_patch(self): if self._patch is not None: self._patch.remove() self._patch = None # Update geometry if not self._roi.defined(): return else: x, y = self._roi.to_polygon() p = MplPath(np.column_stack((x, y))) self._patch = PathPatch(p) self._patch.set_visible(True) # Update appearance self._patch.set(**self.plot_opts) # Refresh self._axes.figure.canvas.draw() def finalize_selection(self, event): self._mid_selection = False if self._patch is not None: self._patch.set_visible(False) self._axes.figure.canvas.draw()
class MplPathROI(MplPolygonalROI): def roi_factory(self): return Path() def _setup_patch(self): self._patch = None def _sync_patch(self): if self._patch is not None: self._patch.remove() self._patch = None # Update geometry if not self._roi.defined(): return else: x, y = self._roi.to_polygon() p = MplPath(np.column_stack((x, y))) self._patch = PathPatch(p) self._patch.set_visible(True) # Update appearance self._patch.set(**self.plot_opts) # Refresh self._axes.figure.canvas.draw() def finalize_selection(self, event): self._mid_selection = False if self._patch is not None: self._patch.set_visible(False) self._axes.figure.canvas.draw()
class MplPathROI(MplPolygonalROI): """ Matplotlib ROI for path selections Parameters ---------- axes : :class:`matplotlib.axes.Axes` The Matplotlib axes to draw to. """ _roi_cls = Path def __init__(self, axes, roi=None): super(MplPolygonalROI, self).__init__(axes) self.plot_opts = { 'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR, 'alpha': 0.3 } self._patch = None def start_selection(self, event): if self._patch is not None: self._patch.remove() self._patch = None self._background_cache = None self._axes.figure.canvas.draw() super(MplPathROI, self).start_selection(event) def _sync_patch(self): if self._patch is not None: self._patch.remove() self._patch = None if self._roi.defined(): x, y = self._roi.to_polygon() p = MplPath(np.column_stack((x, y))) self._patch = PathPatch(p, transform=self._axes.transData) self._patch.set_visible(True) self._patch.set(**self.plot_opts) self._axes.add_artist(self._patch) def finalize_selection(self, event): self._mid_selection = False if self._patch is not None: self._patch.remove() self._patch = None self._draw()
class MplPathROI(MplPolygonalROI): """ Matplotlib ROI for path selections Parameters ---------- axes : `~matplotlib.axes.Axes` The Matplotlib axes to draw to. """ _roi_cls = Path def __init__(self, axes, roi=None): super(MplPolygonalROI, self).__init__(axes) self.plot_opts = {'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR, 'alpha': 0.3} self._patch = None def _sync_patch(self): if self._patch is not None: self._patch.remove() self._patch = None if self._roi.defined(): x, y = self._roi.to_polygon() p = MplPath(np.column_stack((x, y))) self._patch = PathPatch(p) self._patch.set_visible(True) self._patch.set(**self.plot_opts) def finalize_selection(self, event): self._mid_selection = False if self._patch is not None: self._patch.set_visible(False) self._draw()