当前位置: 首页>>代码示例>>Python>>正文


Python widgets.RectangleSelector方法代码示例

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


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

示例1: show

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def show(self):

        self.fig, self.ax = plt.subplots(1, figsize=(11, 8.5))
        _, frame = self.capture.read()
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        self.ax.imshow(frame)

        toggle_selector.RS = RectangleSelector(
            self.ax, self.line_select_callback,
            drawtype='box', useblit=True,
            button=[1], minspanx=5, minspany=5,
            spancoords='pixels', interactive=True,
        )
        self.fig.canvas.mpl_connect('key_press_event', toggle_selector)
        self.fig.canvas.mpl_connect('key_press_event', self.onkeypress)
        plt.tight_layout()
        plt.show()


    # The keybindings attached to the LabelPlot. 
开发者ID:jpnaterer,项目名称:smashscan,代码行数:22,代码来源:label.py

示例2: check_rectangle

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def check_rectangle(**kwargs):
    ax = get_ax()

    def onselect(epress, erelease):
        ax._got_onselect = True
        assert epress.xdata == 100
        assert epress.ydata == 100
        assert erelease.xdata == 199
        assert erelease.ydata == 199

    tool = widgets.RectangleSelector(ax, onselect, **kwargs)
    do_event(tool, 'press', xdata=100, ydata=100, button=1)
    do_event(tool, 'onmove', xdata=199, ydata=199, button=1)

    # purposely drag outside of axis for release
    do_event(tool, 'release', xdata=250, ydata=250, button=1)

    if kwargs.get('drawtype', None) not in ['line', 'none']:
        assert_allclose(tool.geometry,
                        [[100., 100, 199, 199, 100],
                         [100, 199, 199, 100, 100]],
                        err_msg=tool.geometry)

    assert ax._got_onselect 
开发者ID:holzschu,项目名称:python3_ios,代码行数:26,代码来源:test_widgets.py

示例3: __init__

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def __init__(self, fig, **kwargs):
        def on_release(press_event, release_event):
            bbox = np.array([[press_event.xdata, press_event.ydata],
                             [release_event.xdata, release_event.ydata]])
            fig.set_view_bbox(bbox)
            fig.canvas.draw_idle()
            self.rubber_box.disconnect_events()
            fig.connect_events(self.saved_events)
            fig.action_complete()

        self.saved_events = fig.disconnect_events()
        rectprops = dict(edgecolor=fig._rgb['foreground'], fill=False)
        self.rubber_box = widgets.RectangleSelector(
            fig.ax, on_release, drawtype='box', useblit=False,
            button=[1, 3],  # don't use middle button
            minspanx=5, minspany=5, spancoords='pixels', rectprops=rectprops,
            interactive=False) 
开发者ID:mjhoptics,项目名称:ray-optics,代码行数:19,代码来源:interactivefigure.py

示例4: __init__

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def __init__(self, filename):
        self.filename = filename
        self.image_data = cv2.imread(filename, 0)
        fig_image, current_ax = plt.subplots()
        plt.imshow(self.image_data, cmap='gray')
        eh = EventHandler(self.filename)
        rectangle_selector = RectangleSelector(current_ax,
                                               eh.line_select_callback,
                                               drawtype='box',
                                               useblit=True,
                                               button=[1, 2, 3],
                                               minspanx=5, minspany=5,
                                               spancoords='pixels',
                                               interactive=True)
        plt.connect('key_press_event', eh.event_exit_manager)
        plt.show() 
开发者ID:bvnayak,项目名称:PDS_Compute_MTF,代码行数:18,代码来源:PDS_Compute_MTF.py

示例5: show_image

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def show_image(self):
        self.figure, self.axes, self.canvas = self.image_panel.getfigure()
        self.ax = self.axes.imshow(self.image)
        self.figure.canvas.draw()
        self.cid = RectangleSelector(
            self.axes,
            self.line_select_callback,
            drawtype="box",
            useblit=False,
            button=[1],
            minspanx=5,
            minspany=5,
            spancoords="pixels",
            interactive=True,
        )
        self.canvas.mpl_connect("key_press_event", self.cid) 
开发者ID:DeepLabCut,项目名称:DeepLabCut,代码行数:18,代码来源:select_crop_parameters.py

示例6: check_rectangle

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def check_rectangle(**kwargs):
    ax = get_ax()

    def onselect(epress, erelease):
        ax._got_onselect = True
        assert epress.xdata == 100
        assert epress.ydata == 100
        assert erelease.xdata == 199
        assert erelease.ydata == 199

    tool = widgets.RectangleSelector(ax, onselect, **kwargs)
    do_event(tool, 'press', xdata=100, ydata=100, button=1)
    do_event(tool, 'onmove', xdata=199, ydata=199, button=1)

    # purposely drag outside of axis for release
    do_event(tool, 'release', xdata=250, ydata=250, button=1)

    if kwargs.get('drawtype', None) not in ['line', 'none']:
        assert_allclose(tool.geometry,
            [[100., 100, 199, 199, 100], [100, 199, 199, 100, 100]],
            err_msg=tool.geometry)

    assert ax._got_onselect 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:25,代码来源:test_widgets.py

示例7: set_active

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def set_active(self, active):
        """
        Use this to activate / deactivate the RectangleSelector
        from your program with an boolean parameter *active*.
        """
        self.active = active 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:widgets.py

示例8: selectRectangle

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def selectRectangle(axes: Axes = None):
    """ add a rectangle selector to the given axes """
    if axes is None:
        axes = plt.gca()

    def onselect(eclick, erelease):
        'eclick and erelease are matplotlib events at press and release'
        print(' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata))
        print(' endposition   : (%f, %f)' % (erelease.xdata, erelease.ydata))
        print(' used button   : ', eclick.button)

    from matplotlib.widgets import RectangleSelector
    rect_selector = RectangleSelector(axes, onselect)
    return rect_selector 
开发者ID:rgerum,项目名称:pylustrator,代码行数:16,代码来源:helper_functions.py

示例9: toggle_selector

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def toggle_selector(event):
    print(' Key pressed.')
    if event.key in ['Q', 'q'] and toggle_selector.RS.active:
        print(' RectangleSelector deactivated.')
        toggle_selector.RS.set_active(False)
    if event.key in ['A', 'a'] and not toggle_selector.RS.active:
        print(' RectangleSelector activated.')
        toggle_selector.RS.set_active(True) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:10,代码来源:rectangle_selector.py

示例10: test_rectangle_handles

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def test_rectangle_handles():
    ax = get_ax()

    def onselect(epress, erelease):
        pass

    tool = widgets.RectangleSelector(ax, onselect=onselect,
                                     maxdist=10, interactive=True)
    tool.extents = (100, 150, 100, 150)

    assert tool.corners == (
        (100, 150, 150, 100), (100, 100, 150, 150))
    assert tool.extents == (100, 150, 100, 150)
    assert tool.edge_centers == (
        (100, 125.0, 150, 125.0), (125.0, 100, 125.0, 150))
    assert tool.extents == (100, 150, 100, 150)

    # grab a corner and move it
    do_event(tool, 'press', xdata=100, ydata=100)
    do_event(tool, 'onmove', xdata=120, ydata=120)
    do_event(tool, 'release', xdata=120, ydata=120)
    assert tool.extents == (120, 150, 120, 150)

    # grab the center and move it
    do_event(tool, 'press', xdata=132, ydata=132)
    do_event(tool, 'onmove', xdata=120, ydata=120)
    do_event(tool, 'release', xdata=120, ydata=120)
    assert tool.extents == (108, 138, 108, 138)

    # create a new rectangle
    do_event(tool, 'press', xdata=10, ydata=10)
    do_event(tool, 'onmove', xdata=100, ydata=100)
    do_event(tool, 'release', xdata=100, ydata=100)
    assert tool.extents == (10, 100, 10, 100) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:36,代码来源:test_widgets.py

示例11: plot

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def plot(self):
        # Prepare the data
        x = self.locs[self.field_x]
        y = self.locs[self.field_y]
        valid = np.isfinite(x) & np.isfinite(y)
        x = x[valid]
        y = y[valid]
        # Prepare the figure
        self.figure.clear()
        # self.canvas.figure = self.figure
        axes = self.figure.add_subplot(111)
        # Start hist2 version
        bins_x = lib.calculate_optimal_bins(x, 1000)
        bins_y = lib.calculate_optimal_bins(y, 1000)
        counts, x_edges, y_edges, image = axes.hist2d(
            x, y, bins=[bins_x, bins_y], norm=LogNorm()
        )
        x_range = x.ptp()
        axes.set_xlim([bins_x[0] - 0.05 * x_range, x.max() + 0.05 * x_range])
        y_range = y.ptp()
        axes.set_ylim([bins_y[0] - 0.05 * y_range, y.max() + 0.05 * y_range])
        self.figure.colorbar(image, ax=axes)
        axes.grid(False)
        axes.get_xaxis().set_label_text(self.field_x)
        axes.get_yaxis().set_label_text(self.field_y)
        self.selector = RectangleSelector(
            axes,
            self.on_rect_select,
            useblit=False,
            rectprops=dict(facecolor="green", alpha=0.2, fill=True),
        )
        self.canvas.draw() 
开发者ID:jungmannlab,项目名称:picasso,代码行数:34,代码来源:filter.py

示例12: CheckCropping

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def CheckCropping(self):
        """ Display frame at time "time" for video to check if cropping is fine.
        Select ROI of interest by adjusting values in myconfig.py

        USAGE for cropping:
        clip.crop(x1=None, y1=None, x2=None, y2=None, width=None, height=None, x_center=None, y_center=None)

        Returns a new clip in which just a rectangular subregion of the
        original clip is conserved. x1,y1 indicates the top left corner and
        x2,y2 is the lower right corner of the cropped region.

        All coordinates are in pixels. Float numbers are accepted.
        """

        videosource = self.video_source
        self.x1 = int(self.cfg["video_sets"][videosource]["crop"].split(",")[0])
        self.x2 = int(self.cfg["video_sets"][videosource]["crop"].split(",")[1])
        self.y1 = int(self.cfg["video_sets"][videosource]["crop"].split(",")[2])
        self.y2 = int(self.cfg["video_sets"][videosource]["crop"].split(",")[3])

        if self.cropping == True:
            # Select ROI of interest by drawing a rectangle
            self.cid = RectangleSelector(
                self.axes,
                self.line_select_callback,
                drawtype="box",
                useblit=False,
                button=[1],
                minspanx=5,
                minspany=5,
                spancoords="pixels",
                interactive=True,
            )
            self.canvas.mpl_connect("key_press_event", self.cid) 
开发者ID:DeepLabCut,项目名称:DeepLabCut,代码行数:36,代码来源:frame_extraction_toolbox.py

示例13: init_callbacks

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
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,代码行数:53,代码来源:spypylab.py

示例14: draw_bbox

# 需要导入模块: from matplotlib import widgets [as 别名]
# 或者: from matplotlib.widgets import RectangleSelector [as 别名]
def draw_bbox(video):
    import matplotlib.pyplot as plt
    from matplotlib.widgets import RectangleSelector, Button

    clip = cv2.VideoCapture(video)
    if not clip.isOpened():
        print("Video could not be opened. Skipping...")
        return

    success = False
    # Read the video until a frame is successfully read
    while not success:
        success, frame = clip.read()

    bbox = [0, 0, frame.shape[1], frame.shape[0]]

    def line_select_callback(eclick, erelease):
        bbox[:2] = int(eclick.xdata), int(eclick.ydata)  # x1, y1
        bbox[2:] = int(erelease.xdata), int(erelease.ydata)  # x2, y2

    def validate_crop(*args):
        fig.canvas.stop_event_loop()

    def display_help(*args):
        print(
            "1. Use left click to select the region of interest. A red box will be drawn around the selected region. \n\n2. Use the corner points to expand the box and center to move the box around the image. \n\n3. Click "
        )

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.imshow(frame[:, :, ::-1])
    ax_help = fig.add_axes([0.9, 0.2, 0.1, 0.1])
    ax_save = fig.add_axes([0.9, 0.1, 0.1, 0.1])
    crop_button = Button(ax_save, "Crop")
    crop_button.on_clicked(validate_crop)
    help_button = Button(ax_help, "Help")
    help_button.on_clicked(display_help)

    rs = RectangleSelector(
        ax,
        line_select_callback,
        drawtype="box",
        minspanx=5,
        minspany=5,
        interactive=True,
        spancoords="pixels",
        rectprops=dict(facecolor="red", edgecolor="black", alpha=0.3, fill=True),
    )
    plt.show()

    # import platform
    # if platform.system() == "Darwin":  # for OSX use WXAgg
    #    fig.canvas.start_event_loop(timeout=-1)
    # else:
    fig.canvas.start_event_loop(timeout=-1)  # just tested on Ubuntu I also need this.
    #    #fig.canvas.stop_event_loop()

    plt.close(fig)
    return bbox 
开发者ID:DeepLabCut,项目名称:DeepLabCut,代码行数:61,代码来源:auxfun_videos.py


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