• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python widgets.RectangleSelector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib.widgets.RectangleSelector的典型用法代码示例。如果您正苦于以下问题:Python RectangleSelector类的具体用法?Python RectangleSelector怎么用?Python RectangleSelector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了RectangleSelector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, ax, on_move=None, on_release=None, on_enter=None, maxdist=10, rect_props=None):
        CanvasToolBase.__init__(self, ax, on_move=on_move, on_enter=on_enter, on_release=on_release)

        props = dict(edgecolor=None, facecolor="r", alpha=0.15)
        props.update(rect_props if rect_props is not None else {})
        if props["edgecolor"] is None:
            props["edgecolor"] = props["facecolor"]
        RectangleSelector.__init__(self, ax, lambda *args: None, rectprops=props, useblit=self.useblit)
        # Alias rectangle attribute, which is initialized in RectangleSelector.
        self._rect = self.to_draw
        self._rect.set_animated(True)

        self.maxdist = maxdist
        self.active_handle = None
        self._extents_on_press = None

        if on_enter is None:

            def on_enter(extents):
                print("(xmin=%.3g, xmax=%.3g, ymin=%.3g, ymax=%.3g)" % extents)

        self.callback_on_enter = on_enter

        props = dict(mec=props["edgecolor"])
        self._corner_order = ["NW", "NE", "SE", "SW"]
        xc, yc = self.corners
        self._corner_handles = ToolHandles(ax, xc, yc, marker_props=props)

        self._edge_order = ["W", "N", "E", "S"]
        xe, ye = self.edge_centers
        self._edge_handles = ToolHandles(ax, xe, ye, marker="s", marker_props=props)

        self._artists = [self._rect, self._corner_handles.artist, self._edge_handles.artist]
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:33,代码来源:recttool.py


示例2: SeriesWidget

class SeriesWidget(MplWidget):
    def __init__(self, parent=None):
        MplWidget.__init__(self, parent)
        
    def draw(self):
        (self.coord, series, title, xlabel, ylabel, showLegend) = self.inputPorts
        colors = pylab.cm.jet(np.linspace(0,1, series.values.shape[0]))
        
        pylab.clf()
        pylab.title(title)
        ll = pylab.plot(series.values.T, linewidth=1)
        for pos, _ids in enumerate(series.ids):
            ll[pos].set_color(colors[pos])
            if _ids in self.selectedIds:
                ll[pos].set_linewidth(3)
        pylab.xlabel(xlabel)
        pylab.ylabel(ylabel)

        if showLegend:
            pylab.legend(pylab.gca().get_lines(),
                         series.labels,
                         numpoints=1, prop=dict(size='small'), loc='upper right')
                
        self.figManager.canvas.draw()
        self.rectSelector = RectangleSelector(pylab.gca(), self.onselect, drawtype='box', 
                                              rectprops=dict(alpha=0.4, facecolor='yellow'))
        self.rectSelector.set_active(True)

    def updateSelection(self, selectedIds):
        self.selectedIds = selectedIds
        self.updateContents();
    
    def onselect(self, eclick, erelease):
        pass
开发者ID:imclab,项目名称:vistrails,代码行数:34,代码来源:plots.py


示例3: PeakFinder

class PeakFinder(object):
    def __init__(self, ax, canvas):
        self.rectProps  = dict(facecolor='red', edgecolor = 'white',
                 alpha=0.5, fill=True)
        self.indicatorProps = dict(facecolor='white', edgecolor='black', alpha=0.5, fill=True)
        self.__selector = RectangleSelector(ax, self.onSelect, drawtype='box', rectprops=self.rectProps)
        self.__axes     = ax
        self.__canvas   = canvas
        
    def onSelect(self, epress, erelease):
        start   = map(int, (epress.xdata, epress.ydata))
        stop    = map(int, (erelease.xdata, erelease.ydata))
        ###################
        ax      = self.__axes
        dataMatrix  = ax.get_axes().get_images()[0].get_array()
        clipMatrix  = dataMatrix[start[1]:(stop[1]+1), start[0]:(stop[0]+1)]
        peakPos     = nonzero(clipMatrix == clipMatrix.max())
        peakPos     = (peakPos[1][0] + start[0], peakPos[0][0] + start[1])
        print peakPos
        circle      = Circle(peakPos, 4, **self.indicatorProps)
        ax.add_patch(circle)
        self.__canvas.show()
        ###################
    
    def activate(self):
        self.__selector.set_active(True)
        
    def deactivate(self):
        self.__selector.set_active(False)
        
    @property
    def isActivate(self):
        return self.__selector.active
开发者ID:hitwhphk,项目名称:WaveSyn,代码行数:33,代码来源:imagetools.py


示例4: __init__

 def __init__(self, lines, drawtype='box',
              minspanx=None, minspany=None, useblit=False,
              lineprops=None, rectprops=None, spancoords='data',
              button=None, maxdist=10, marker_props=None,
              interactive=False, state_modifier_keys=None):
     
     self.verbose = True
     self.lines = flatten(lines)
     ax = self.lines[0].axes
     
     RectangleSelector.__init__( self, ax, self.select_lines, drawtype,
                                     minspanx, minspany, useblit,
                                     lineprops, rectprops, spancoords,
                                     button, maxdist, marker_props,
                                     interactive, state_modifier_keys)
 
     hprops = dict(linewidth=10, alpha=0.5, linestyle='-') # marker='s'
     self.selection = [ np.zeros(l.get_xdata().shape, bool) 
                         for l in self.lines ]
     
     #Create Line2D for highlighting selected sections
     self.highlighted = []
     for line in self.lines:
         hline, = ax.plot([], [], color=line.get_color(), **hprops)
         self.highlighted.append( hline )
         self.artists.append( hline )       #enable blitting for the highlighted segments
开发者ID:apodemus,项目名称:grafico,代码行数:26,代码来源:interactive.py


示例5: __init__

    def __init__(
        self,
        ax,
        onselect,
        button=None,
        minspanx=None,
        minspany=None,
        useblit=True,
        lineprops=None,
        rectprops=dict(facecolor="red", edgecolor="black", alpha=0.5, fill=True),
        proxy=5,
    ):
        RectangleSelector.__init__(
            self,
            ax=ax,
            onselect=onselect,
            drawtype="box",
            spancoords="data",
            minspanx=minspanx,
            minspany=minspany,
            useblit=useblit,
            lineprops=lineprops,
            rectprops=rectprops,
            button=button,
        )

        self.fixedSize = None
        self.prevEvents = None
        self.proxy = max(
            self.ax.transData.transform_point((proxy / 100, proxy / 100)) - self.ax.transData.transform_point((0, 0))
        )
开发者ID:jochym,项目名称:pointsel,代码行数:31,代码来源:pointsel.py


示例6: onmove

 def onmove(self, ev):
     if self.eventpress is None or self.ignore(ev):
         return
     if self.fixedSize and self.prevEvents:
         # Panning mode. Modify the existing ROI. Do the shift.
         ev.xdata += self.wdata
         ev.ydata += self.hdata
         self.eventpress.xdata = ev.xdata - 2 * self.wdata
         self.eventpress.ydata = ev.ydata - 2 * self.hdata
     RectangleSelector.onmove(self, ev)
开发者ID:jochym,项目名称:pointsel,代码行数:10,代码来源:pointsel.py


示例7: _press

 def _press(self, event):
     if event.button == 1:
         pass
     
     if event.button == 2:
         self.restart()
         self.canvas.draw()          #TODO: blit
         return
     
     RectangleSelector._press(self, event)
开发者ID:apodemus,项目名称:grafico,代码行数:10,代码来源:interactive.py


示例8: on_mouse_press

 def on_mouse_press(self, event):
     if event.button != 1 or not self.ax.in_axes(event):
         return
     self._set_active_handle(event)
     if self.active_handle is None:
         # Clear previous rectangle before drawing new rectangle.
         self.set_visible(False)
         self.redraw()
     self.set_visible(True)
     RectangleSelector.press(self, event)
开发者ID:haohao200609,项目名称:Hybrid,代码行数:10,代码来源:recttool.py


示例9: SelectFromCollection

class SelectFromCollection(object):
    """Select indices from a matplotlib collection using `LassoSelector`.

    Selected indices are saved in the `ind` attribute. This tool highlights
    selected points by fading them out (i.e., reducing their alpha values).
    If your collection has alpha < 1, this tool will permanently alter them.

    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`.
    """

    def __init__(self, ax, collection, alpha_other=0.3):
        self.canvas = ax.figure.canvas
        self.collection = collection
        self.alpha_other = alpha_other

        self.xys = collection.get_offsets()
        self.Npts = len(self.xys)

        # Ensure that we have separate colors for each object
        self.fc = collection.get_facecolors()
        if len(self.fc) == 0:
            raise ValueError('Collection must have a facecolor')
        elif len(self.fc) == 1:
            self.fc = np.tile(self.fc, self.Npts).reshape(self.Npts, -1)

        self.lasso = RectangleSelector(ax, onselect=self.onselect)  # Sprememba glede na originalno kodo
        self.ind = []

    def onselect(self, verts):
        path = Path(verts)
        self.ind = np.nonzero([path.contains_point(xy) for xy in self.xys])[0]
        self.fc[:, -1] = self.alpha_other
        self.fc[self.ind, -1] = 1
        self.collection.set_facecolors(self.fc)
        self.canvas.draw_idle()

    def disconnect(self):
        self.lasso.disconnect_events()
        self.fc[:, -1] = 1
        self.collection.set_facecolors(self.fc)
        self.canvas.draw_idle()
开发者ID:Ossada,项目名称:DLS-UVVis,代码行数:54,代码来源:test_selektor.py


示例10: on_mouse_release

 def on_mouse_release(self, event):
     if event.button != 1:
         return
     if not self.ax.in_axes(event):
         self.eventpress = None
         return
     RectangleSelector.release(self, event)
     self._extents_on_press = None
     # Undo hiding of rectangle and redraw.
     self.set_visible(True)
     self.redraw()
     self.callback_on_release(self.geometry)
开发者ID:haohao200609,项目名称:Hybrid,代码行数:12,代码来源:recttool.py


示例11: press

 def press(self, ev):
     if self.ignore(ev):
         return
     h = self.close_to_handles(ev)
     if not self.fixedSize and self.prevEvents and h:
         # Not fixed size and active roi.
         # Clicked on the corner -> modify mode
         x, y = self.opposite_corner(h)
         self.to_draw.set_visible(self.visible)
         self.eventpress = ev
         self.eventpress.xdata = x
         self.eventpress.ydata = y
         return False
     else:
         RectangleSelector.press(self, ev)
开发者ID:jochym,项目名称:pointsel,代码行数:15,代码来源:pointsel.py


示例12: release

    def release(self, ev):
        if self.eventpress is None or self.ignore(ev):
            return
        if self.fixedSize and self.prevEvents:
            # Panning mode. Modify the existing ROI. Do the shift.
            ev.xdata += self.wdata
            ev.ydata += self.hdata
            self.eventpress.xdata = ev.xdata - 2 * self.wdata
            self.eventpress.ydata = ev.ydata - 2 * self.hdata

        self.prevEvents = (self.eventpress, ev)
        pe, re = self.prevEvents
        self.wdata = (pe.xdata - re.xdata) / 2
        self.hdata = (pe.ydata - re.ydata) / 2
        RectangleSelector.release(self, ev)
开发者ID:jochym,项目名称:pointsel,代码行数:15,代码来源:pointsel.py


示例13: __init__

 def __init__(self, ax, canvas):
     self.rectProps  = dict(facecolor='red', edgecolor = 'white',
              alpha=0.5, fill=True)
     self.indicatorProps = dict(facecolor='white', edgecolor='black', alpha=0.5, fill=True)
     self.__selector = RectangleSelector(ax, self.onSelect, drawtype='box', rectprops=self.rectProps)
     self.__axes     = ax
     self.__canvas   = canvas
开发者ID:hitwhphk,项目名称:WaveSyn,代码行数:7,代码来源:imagetools.py


示例14: __init__

 def __init__(self,artist):
         self.artist = artist
         self.selector = RectangleSelector(self.artist.axes,self.on_select,
                                    button=3, minspanx=5, minspany=5, spancoords='pixels',
                                    rectprops = dict(facecolor='red', edgecolor = 'red',
                                                     alpha=0.3, fill=True))
         self.coords = []
开发者ID:TomFarley,项目名称:Fast_cameras,代码行数:7,代码来源:utils.py


示例15: __init__

    def __init__(self, viewer, on_move=None, on_release=None, on_enter=None,
                 maxdist=10, rect_props=None):
        self._rect = None
        props = dict(edgecolor=None, facecolor='r', alpha=0.15)
        props.update(rect_props if rect_props is not None else {})
        if props['edgecolor'] is None:
            props['edgecolor'] = props['facecolor']
        RectangleSelector.__init__(self, viewer.ax, lambda *args: None,
                                   rectprops=props)
        CanvasToolBase.__init__(self, viewer, on_move=on_move,
                                on_enter=on_enter, on_release=on_release)

        # Events are handled by the viewer
        try:
            self.disconnect_events()
        except AttributeError:
            # disconnect the events manually (hack for older mpl versions)
            [self.canvas.mpl_disconnect(i) for i in range(10)]

        # Alias rectangle attribute, which is initialized in RectangleSelector.
        self._rect = self.to_draw
        self._rect.set_animated(True)

        self.maxdist = maxdist
        self.active_handle = None
        self._extents_on_press = None

        if on_enter is None:
            def on_enter(extents):
                print("(xmin=%.3g, xmax=%.3g, ymin=%.3g, ymax=%.3g)" % extents)
        self.callback_on_enter = on_enter

        props = dict(mec=props['edgecolor'])
        self._corner_order = ['NW', 'NE', 'SE', 'SW']
        xc, yc = self.corners
        self._corner_handles = ToolHandles(self.ax, xc, yc, marker_props=props)

        self._edge_order = ['W', 'N', 'E', 'S']
        xe, ye = self.edge_centers
        self._edge_handles = ToolHandles(self.ax, xe, ye, marker='s',
                                         marker_props=props)

        self.artists = [self._rect,
                        self._corner_handles.artist,
                        self._edge_handles.artist]
        viewer.add_tool(self)
开发者ID:haohao200609,项目名称:Hybrid,代码行数:46,代码来源:recttool.py


示例16: __init__

    def __init__(self, ax=None):
        if ax is None: ax=gca()
        self.ax = ax

        # drawtype is 'box' or 'line' or 'none'
        self.selector = RectangleSelector(self.ax, self._callback,
                               drawtype='box',useblit=True,
                               minspanx=5,minspany=5,spancoords='pixels')
        self.selector.set_active(False)
        self.block = BlockingInput(self.ax.figure)
开发者ID:reflectometry,项目名称:osrefl,代码行数:10,代码来源:ginput_rect.py


示例17: ROISelector

class ROISelector(object):
    
    def __init__(self,artist):
            self.artist = artist
            self.selector = RectangleSelector(self.artist.axes,self.on_select,
                                       button=3, minspanx=5, minspany=5, spancoords='pixels',
                                       rectprops = dict(facecolor='red', edgecolor = 'red',
                                                        alpha=0.3, fill=True))
            self.coords = []
            
    def on_select(self,click,release):
            x1,y1 = int(click.xdata),int(click.ydata)
            x2,y2 = int(release.xdata),int(release.ydata)
            self.coords =[(x1,y1),(x2,y2)]
            
    def activate(self):
        self.selector.set_active(True)
        
    def deactivate(self):
        self.selector.set_active(False)        
开发者ID:TomFarley,项目名称:Fast_cameras,代码行数:20,代码来源:utils.py


示例18: __init__

 def __init__(self, fitsfile, ax, mags, frms, all_axes, buttons, use_hjd=False,
         display_class=LightcurveDisplay):
     self.fitsfile = fitsfile
     self.ax = ax
     self.mags = mags
     self.frms = frms
     self.all_axes = all_axes
     self.buttons = buttons
     self.use_hjd = use_hjd
     self.display_class = display_class
     self.selector = RectangleSelector(self.ax, self.on_event, drawtype='box')
     self.l = None
开发者ID:mindriot101,项目名称:lightcurve-visualisation,代码行数:12,代码来源:analysis.py


示例19: _line_selector

    def _line_selector(self):
        try:
            self.rs.disconnect_events()
            DraggableResizeableRectangle.lock = True
            print('Rectangles are locked')

        except:
            print('Rectangles could not be locked')

        print(self.__class__.__name__, ": Connecting Line Selector")
        DraggableResizeableLine.lock = None
        self.ls = RectangleSelector(self.axes_selector, self.line_selector_func, drawtype='line', useblit=True, button=[3])
开发者ID:SirJohnFranklin,项目名称:TraitsMatplotlibWidget,代码行数:12,代码来源:TraitsMPLWidget.py


示例20: init_callbacks

    def init_callbacks(self):
        '''Creates the object's callback registry and default callbacks.'''
        from spectral import settings
        from matplotlib.cbook import CallbackRegistry
        
        self.callbacks = CallbackRegistry()

        # callbacks_common may have been set to a shared external registry
        # (e.g., to the callbacks_common member of another ImageView object). So
        # don't create it if it has already been set.
        if self.callbacks_common is None:
            self.callbacks_common = CallbackRegistry()

        # Keyboard callback
        self.cb_mouse = ImageViewMouseHandler(self)
        self.cb_mouse.connect()

        # Mouse callback
        self.cb_keyboard = ImageViewKeyboardHandler(self)
        self.cb_keyboard.connect()

        # Class update event callback
        def updater(*args, **kwargs):
            if self.classes is None:
                self.set_classes(args[0].classes)
            self.refresh()
        callback = MplCallback(registry=self.callbacks_common,
                               event='spy_classes_modified',
                               callback=updater)
        callback.connect()
        self.cb_classes_modified = callback


        if settings.imshow_enable_rectangle_selector is False:
            return
        try:
            from matplotlib.widgets import RectangleSelector
            self.selector = RectangleSelector(self.axes,
                                              self._select_rectangle,
                                              button=1,
                                              useblit=True,
                                              spancoords='data',
                                              drawtype='box',
                                              rectprops = \
                                                  self.selector_rectprops)
            self.selector.set_active(False)
        except:
            self.selector = None
            msg = 'Failed to create RectangleSelector object. Interactive ' \
              'pixel class labeling will be unavailable.'
            warn(msg)
开发者ID:spectralpython,项目名称:spectral,代码行数:51,代码来源:spypylab.py



注:本文中的matplotlib.widgets.RectangleSelector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python widgets.Slider类代码示例发布时间:2022-05-27
下一篇:
Python widgets.RadioButtons类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap