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


Python Rectangle.set_width方法代码示例

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


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

示例1: Selector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class Selector(object):
    def __init__(self, ax):
        self.ax = ax
        
        self.x0 = None
        self.y0 = None
        
        self.rect = Rectangle((0,0), 1, 1, fill=False)
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)

    def on_press(self, event):
        self.x0 = event.xdata
        self.y0 = event.ydata

    def on_release(self, event):
        x1 = event.xdata
        y1 = event.ydata

        self.rect.set_width(x1 - self.x0)
        self.rect.set_height(y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.ax.figure.canvas.draw()
        
        x_min = min(self.x0, x1)
        x_max = max(self.x0, x1)
        y_min = min(self.y0, y1)
        y_max = max(self.y0, y1)

        self.xybounds = (x_min, x_max, y_min, y_max)
开发者ID:robz,项目名称:OpenCV_Matplotlib_Tests,代码行数:33,代码来源:threshold_finder.py

示例2: LaneSelector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class LaneSelector(object):
    def __init__(self, cb):
        self.ax = gca()
        self.rect = Rectangle((0,0), 1, 1, alpha=0.2, color='red')
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.pressed = False
        self.cb = cb
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
        self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)

    def on_press(self, event):
        self.x0 = event.xdata
        self.y0 = event.ydata
        self.pressed = True

    def on_release(self, event):
        self.pressed = False
        if self.x0 != self.x1 and self.y0 != self.y1:
            self.cb(self.x0, self.y0, self.x1, self.y1)

    def on_motion(self, event):
        if self.pressed:
            self.x1 = event.xdata
            self.y1 = event.ydata
            self.rect.set_width(self.x1 - self.x0)
            self.rect.set_height(self.y1 - self.y0)
            self.rect.set_xy((self.x0, self.y0))
            self.ax.figure.canvas.draw()
开发者ID:etlapale,项目名称:wblanes,代码行数:35,代码来源:wblanes.py

示例3: close

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class click_window:
   '''An interactive window.  Given an axis instance and a start point
   (x0,y0), draw a dynamic rectangle that follows the mouse until
   the close() function is called (which returns the coordinates of
   the final rectangle.  Useful or selecting out square regions.'''

   def __init__(self, ax, x0, y0):
      self.ax = ax
      self.x0 = x0
      self.y0 = y0
      self.rect = Rectangle((x0,y0), width=0, height=0, alpha=0.1)
      ax.add_artist(self.rect)

   def connect(self):
      self.cidmotion = self.rect.figure.canvas.mpl_connect(
            'motion_notify_event', self.on_motion)

   def on_motion(self, event):
      # Have we left the axes?
      if event.inaxes != self.rect.axes:  return

      self.rect.set_width(event.xdata - self.x0)
      self.rect.set_height(event.ydata - self.y0)
      self.ax.figure.canvas.draw()

   def close(self):
      self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
      extent = self.rect.get_bbox().get_points()
      self.rect.remove()
      self.ax.figure.canvas.draw()
      return(list(ravel(extent)))
开发者ID:obscode,项目名称:snpy,代码行数:33,代码来源:plot_sne_mpl.py

示例4: __init__

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class click_xrange:
   '''An interactive xrange selector.  Given an axis and a starting
   x0 location, draw a full-height rectange that follows the mouise.
   Similar to click_window, but more appropriate for selecting out
   an x-range.'''

   def __init__(self, ax, x0):
      self.ax = ax
      self.x0 = x0
      y0,y1 = ax.get_ybound()
      self.rect = Rectangle((x0,y0), width=0, height=(y1-y0), alpha=0.1)
      ax.add_artist(self.rect)

   def connect(self):
      self.cidmotion = self.rect.figure.canvas.mpl_connect(
            'motion_notify_event', self.on_motion)

   def on_motion(self, event):
      # Have we left the axes?
      if event.inaxes != self.rect.axes:  return

      self.rect.set_width(event.xdata - self.x0)
      self.ax.figure.canvas.draw()

   def close(self):
      self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
      self.rect.remove()
      self.ax.figure.canvas.draw()
      return(self.x0, self.rect.get_x()+self.rect.get_width())
开发者ID:obscode,项目名称:snpy,代码行数:31,代码来源:plot_sne_mpl.py

示例5: resizeGraphics

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
    def resizeGraphics(self, width, height):

        """ It is time to set a magnitude to our currently normalized
            lines, and send them to the figure. Here we assume that
            __normLines & __normPatches are already fully populated. """
        self.__fig.lines   = [] # clear all old lines from figure
        self.__fig.patches = [] # clear all old patches from figure
        self.__xsz = width
        self.__ysz = height

        # scale each text item
        for t in self.__fig.texts:
            t.set_size(self.getTextPointSize(t.gkiTextSzFactor, width, height))

        # scale each line, then apply it to the figure
        for nrln in self.__normLines:
            ll = Line2D([], [])
            ll.update_from(nrln)
            ll.set_data(nrln.get_xdata(True)*self.__xsz,
                        nrln.get_ydata(True)*self.__ysz)
            self.__fig.lines.append(ll)

        # scale each patch, then apply it to the figure
        for nrpa in self.__normPatches:
            rr = Rectangle((0,0),0,0)
            rr.update_from(nrpa)
            rr.set_x(nrpa.get_x()*self.__xsz)
            rr.set_y(nrpa.get_y()*self.__ysz)
            rr.set_width(nrpa.get_width()*self.__xsz)
            rr.set_height(nrpa.get_height()*self.__ysz)
            self.__fig.patches.append(rr)
开发者ID:jhunkeler,项目名称:pyraf,代码行数:33,代码来源:GkiMpl.py

示例6: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class Annotate(object):
    def __init__(self, ax):
        self.ax = ax
        self.rect = Rectangle((0,0), 1, 1, fill=False)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)

    def on_press(self, event):
        print 'press'
        self.x0 = event.xdata
        self.y0 = event.ydata

    def on_release(self, event):
        print 'release'
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.ax.figure.canvas.draw()
        self.get_graph_bound()
        #self.bounds = ColorBounds(Cb_min=self.x0, Cr_min=self.y0, Cb_max=self.x1, Cr_max=self.y1)
        self.bounds = ColorBounds(Cr_min=self.x0, Yp_min=self.y0, Cr_max=self.x1, Yp_max=self.y1)
        
    def get_graph_bound(self):
        print(self.x0, self.y0, self.x1, self.y1)
开发者ID:robz,项目名称:OpenCV_Matplotlib_Tests,代码行数:33,代码来源:opencv_test2.py

示例7: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class Annotate(object):
    def __init__(self):
        self.ax = plt.gca()
        self.rect = Rectangle((0,0), 1, 1)
        self.x0 = None         
        self.y0 = None         
        self.x1 = None         
        self.y1 = None         
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
       
   
    def on_press(self, event):
        print 'press'         
        self.x0 = event.xdata         
        self.y0 = event.ydata      
       
       
    def on_release(self, event):         
        print 'release'         
        self.x1 = event.xdata         
        self.y1 = event.ydata         
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)         
        self.rect.set_xy((self.x0, self.y0))         
        self.ax.figure.canvas.draw()  
开发者ID:zzucainiao,项目名称:code-backup,代码行数:29,代码来源:huatu.py

示例8: MplYRangeROI

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class MplYRangeROI(AbstractMplRoi):

    def __init__(self, ax):
        """
        :param ax: A matplotlib Axes object to attach the graphical ROI to
        """

        AbstractMplRoi.__init__(self, ax)
        self._xi = None

        self.plot_opts = {'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR,
                          'alpha': 0.3}

        trans = blended_transform_factory(self._ax.transAxes,
                                          self._ax.transData)
        self._patch = Rectangle((0., 0.), 1., 1., transform=trans)
        self._patch.set_zorder(100)
        self._setup_patch()

    def _setup_patch(self):
        self._ax.add_patch(self._patch)
        self._patch.set_visible(False)
        self._sync_patch()

    def _roi_factory(self):
        return YRangeROI()

    def start_selection(self, event):
        if event.inaxes != self._ax:
            return

        self._roi.reset()
        self._roi.set_range(event.ydata, event.ydata)
        self._xi = event.ydata
        self._mid_selection = True
        self._sync_patch()

    def update_selection(self, event):
        if not self._mid_selection or event.inaxes != self._ax:
            return
        self._roi.set_range(min(event.ydata, self._xi),
                            max(event.ydata, self._xi))
        self._sync_patch()

    def finalize_selection(self, event):
        self._mid_selection = False
        self._patch.set_visible(False)
        self._draw()

    def _sync_patch(self):
        if self._roi.defined():
            rng = self._roi.range()
            self._patch.set_xy((0, rng[0]))
            self._patch.set_height(rng[1] - rng[0])
            self._patch.set_width(1)
            self._patch.set(**self.plot_opts)
            self._patch.set_visible(True)
        else:
            self._patch.set_visible(False)
        self._draw()
开发者ID:hayd,项目名称:glue,代码行数:62,代码来源:roi.py

示例9: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class Annotate(object):
    def __init__(self):
        self.ax = plt.gca()
        #self.ax = ax
        #self.fig = fig
        self.rect = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.is_pressed = False
        self.ax.add_patch(self.rect)
        #self.fig.canvas.mpl_connect('button_press_event',self.on_press)
        #self.fig.canvas.mpl_connect('button_release_event', self.on_release)
        #self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion)
        
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
        self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
        self.ax.figure.canvas.draw()
    def on_press(self, event):
        print 'press'
        self.is_pressed = True
        self.x0 = event.xdata
        self.y0 = event.ydata
        print self.x0, self.y0
        #self.rect.set_width(self.x1 - self.x0)
        #self.rect.set_height(self.y1 - self.y0)
        #self.rect.set_xy((self.x0, self.y0))
        #self.rect.set_linestyle('dashed')
        #self.fig.canvas.draw()
        #self.ax.figure.canvas.draw()
    def on_motion(self,event):
        print 'motion'
        if self.is_pressed is True:
            return
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.rect.set_linestyle('dashed')
        #self.fig.canvas.draw()
        self.ax.figure.canvas.draw()
    def on_release(self, event):
        print 'release'
        self.is_pressed = False
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.rect.set_linestyle('solid')
        #self.fig.canvas.draw()
        self.ax.figure.canvas.draw()
        #time.sleep(3)
        #plt.close()
        print self.x0,self.y0,self.x1,self.y1
开发者ID:clarehchao,项目名称:python-DrawROI,代码行数:60,代码来源:Annotate.py

示例10: RoiRect

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class RoiRect(object):
    ''' Class for getting a mouse drawn rectangle
    Based on the example from:
    http://matplotlib.org/users/event_handling.html#draggable-rectangle-exercise
    Note that:
    
    * It makes only one roi
    
    '''
    def __init__(self):
        self.ax = plt.gca()
        self.rect = Rectangle((0,0), 1, 1,fc='none', ec='r')
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
        self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)

    def on_press(self, event):
        print 'press'
        self.x0 = event.xdata
        self.y0 = event.ydata
        self.rect.set_linestyle('dashed')
        self.set = False

    def on_release(self, event):
        print 'release'
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.rect.set_linestyle('solid')
        self.ax.figure.canvas.draw()
        self.set = True
        self.ax.figure.canvas.mpl_disconnect(self.on_press)
        self.ax.figure.canvas.mpl_disconnect(self.on_release)
        self.ax.figure.canvas.mpl_disconnect(self.on_motion)
        
    def on_motion(self, event):
        # on motion will move the rect if the mouse
        if self.x0 is None: return
        if self.set: return
        # if event.inaxes != self.rect.axes: return
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.ax.figure.canvas.draw()
开发者ID:ERCpy,项目名称:ercpy,代码行数:55,代码来源:utils.py

示例11: RectangleRegionSelector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class RectangleRegionSelector(object):
    isPressed = False

    def __init__(self):
        self.ax = plt.gca()
        self.rect = Rectangle((0, 0), 1, 1, color='b', fill=False)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event',
                                          self.on_release)
        self.ax.figure.canvas.mpl_connect('motion_notify_event',
                                          self.on_motion)

    def on_press(self, event):
        self.x0 = event.xdata
        self.y0 = event.ydata
        self.isPressed = True

    def on_motion(self, event):
        if self.isPressed:
            self.x1 = event.xdata
            self.y1 = event.ydata
            self.draw_rect()

    def on_release(self, event):
        self.isPressed = False
        if event.xdata is not None and event.ydata is not None:
            self.x1 = event.xdata
            self.y1 = event.ydata
            self.draw_rect()
        else:
            print "Mouse must be released within the axes, try again."

    def draw_rect(self):
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.ax.figure.canvas.draw()

    def asXYWH(self):
        return (min(self.x0, self.x1), min(self.y0, self.y1),
                abs(self.x1-self.x0), abs(self.y1-self.y0))
开发者ID:stephenhelms,项目名称:WormTracker,代码行数:48,代码来源:roitools.py

示例12: rectSelection

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class rectSelection(GuiSelection):
    """Interactive selection of a rectangular region on the axis.

    Used by hist2d_alex().
    """
    def on_press_draw(self):
        if 'r' in self.__dict__:
            self.r.set_height(0)
            self.r.set_width(0)
            self.r.set_xy((self.xs, self.ys))
            self.e.height = 0
            self.e.width = 0
            self.e.center = (self.xs, self.ys)
        else:
            self.r = Rectangle(xy=(self.xs, self.ys), height=0, width=0,
                               fill=False, lw=2, alpha=0.5, color='blue')
            self.e = Ellipse(xy=(self.xs, self.ys), height=0, width=0,
                    fill=False, lw=2, alpha=0.6, color='blue')
            self.ax.add_artist(self.r)
            self.ax.add_artist(self.e)
            self.r.set_clip_box(self.ax.bbox)
            self.r.set_zorder(10)
            self.e.set_clip_box(self.ax.bbox)
            self.e.set_zorder(10)

    def on_motion_draw(self):
        self.r.set_height(self.ye - self.ys)
        self.r.set_width(self.xe - self.xs)
        self.e.height = (self.ye - self.ys)
        self.e.width = (self.xe - self.xs)
        self.e.center = (np.mean([self.xs, self.xe]),
                         np.mean([self.ys, self.ye]))
        self.fig.canvas.draw()

    def on_release_print(self):
        # This is the only custom method for hist2d_alex()
        E1, E2 = min((self.xs, self.xe)), max((self.xs, self.xe))
        S1, S2 = min((self.ys, self.ye)), max((self.ys, self.ye))
        self.selection = dict(E1=E1, E2=E2, S1=S1, S2=S2)
        pprint("Selection: \nE1=%.2f, E2=%.2f, S1=%.2f, S2=%.2f\n" %\
                (E1,E2,S1,S2))
开发者ID:pkw0818,项目名称:FRETBursts,代码行数:43,代码来源:gui_selection.py

示例13: xspanSelection

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class xspanSelection(GuiSelection):
    """Interactive selection of an x range on the axis"""
    def on_press_draw(self):
        if 'r' in self.__dict__:
            self.r.set_width(0)
            self.r.set_xy((self.xs, self.ax.get_ylim()[0]))
            self.r.set_height(self.ax.get_ylim()[1] - self.ax.get_ylim()[0])
        else:
            self.r = Rectangle(xy=(self.xs, self.ax.get_ylim()[0]),
                               height=self.ax.get_ylim()[1] - \
                                      self.ax.get_ylim()[0],
                               width=0, fill=True, lw=2, alpha=0.5,
                               color='blue')
            self.ax.add_artist(self.r)
            self.r.set_clip_box(self.ax.bbox)
            self.r.set_zorder(10)

    def on_motion_draw(self):
        self.r.set_width(self.xe - self.xs)

    def on_release_print(self):
        pprint('X Span: (%d, %d)\n' % (self.xs, self.xe))
开发者ID:pkw0818,项目名称:FRETBursts,代码行数:24,代码来源:gui_selection.py

示例14: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class Annotate(object):
    def __init__(self,ax=None):
        if ax==None:
            self.ax = plt.gca()
        else:
            self.ax = ax
        self.rect = Rectangle((0,0), 0, 0, facecolor='yellow', edgecolor='yellow', alpha=.5, \
                                  zorder=10, clip_on=False)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.is_pressed = False
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
        self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
    def on_press(self, event):
        self.is_pressed = True
        print 'press'
        self.x0 = event.xdata
        self.y0 = event.ydata    
        self.x1 = event.xdata
        self.y1 = event.ydata
        if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
            self.rect.set_width(self.x1 - self.x0)
            self.rect.set_height(self.y1 - self.y0)
            self.rect.set_xy((self.x0, self.y0))
            self.rect.set_linestyle('dashed')
        self.ax.figure.canvas.draw()
    def on_motion(self,event):
        if self.is_pressed is True:
            self.x1 = event.xdata
            self.y1 = event.ydata
            if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
                self.rect.set_width(self.x1 - self.x0)
                self.rect.set_height(self.y1 - self.y0)
                self.rect.set_xy((self.x0, self.y0))
                self.rect.set_linestyle('dashed')
                self.ax.figure.canvas.draw()
    def on_release(self, event):
        self.is_pressed = False
        print 'release'
        self.x1 = event.xdata
        self.y1 = event.ydata
        if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
            self.rect.set_width(self.x1 - self.x0)
            self.rect.set_height(self.y1 - self.y0)
            self.rect.set_xy((self.x0, self.y0))
            self.rect.set_linestyle('solid')
            self.ax.figure.canvas.draw()
        print self.x0,self.y0,self.x1,self.y1
        
        if self.x0==self.x1 and self.y0==self.y1:
            print type(self.__bases__)
开发者ID:kiwimatto,项目名称:2dpolim-analysis,代码行数:57,代码来源:spot_picker.py

示例15: PlotInterface

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_width [as 别名]
class PlotInterface(object):
    def __init__(self, df, EvT_color_set, EvT_size_set):
        self.df = df
        self.ax = plt.gca()
        self.rect = Rectangle((0.1,0.1), 0, 0, fill=False)
        self.rect.set_visible(False)
        self.ax.add_patch(self.rect)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.press = False
        self.sub_df = None
        self.EvT_color_set = EvT_color_set
        self.EvT_size_set = EvT_size_set
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('motion_notify_event',self.on_motion)
        self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
        
    def on_press(self, event):
        if event.inaxes:
            
            self.press = True
            self.x0 = event.xdata
            self.y0 = event.ydata
            self.rect.set_width(0)
            self.rect.set_height(0)
            self.rect.set_xy((self.x0,self.y0))
            self.rect.set_visible(True)
            #Save the plot background
            self.background = self.ax.figure.canvas.copy_from_bbox(self.ax.bbox)
            


    def on_release(self, event):
        if event.inaxes:
            self.press = False
            self.x1 = event.xdata
            self.y1 = event.ydata
            self.rect.set_visible(False)
            self.ax.figure.canvas.draw()
            self.min_x = min(self.x0,self.x1)
            self.max_x = max(self.x0,self.x1)
            self.min_y = min(self.y0,self.y1)
            self.max_y = max(self.y0,self.y1)
            
            if self.sub_df is not None:
                self.sub_df = self.sub_df.append(self.df[ (self.df['timestamp'] > self.min_x) & (self.df['timestamp'] < self.max_x) & \
                                 (self.df['amplitude'] > self.min_y) & (self.df['amplitude'] < self.max_y)])
            else:
                self.sub_df = self.df[ (self.df['timestamp'] > self.min_x) & (self.df['timestamp'] < self.max_x) & \
                                 (self.df['amplitude'] > self.min_y) & (self.df['amplitude'] < self.max_y)]            
            
            plt.scatter(self.sub_df['timestamp'],self.sub_df['amplitude'],color='blue',s=self.EvT_size_set)  
            self.ax.figure.canvas.draw()

            print('Selected (%d < timestamp < %d) and (%d < amplitude < %d)' % (self.min_x, self.max_x, self.min_y, self.max_y))
            
    def on_motion(self, event):
        if self.press is False: return
        if event.inaxes != self.rect.axes: return
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rect.set_width(self.x1 - self.x0)
        self.rect.set_height(self.y1 - self.y0)
        self.rect.set_xy((self.x0, self.y0))
        self.ax.figure.canvas.restore_region(self.background)
        self.ax.draw_artist(self.rect)
        self.ax.figure.canvas.blit(self.rect.clipbox)
开发者ID:Raknoche,项目名称:MyCode,代码行数:71,代码来源:radonGUI.py


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