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


Python Rectangle.set_xy方法代码示例

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


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

示例1: LaneSelector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例2: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例3: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例4: MplYRangeROI

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例5: Selector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例6: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例7: RoiRect

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例8: RectangleRegionSelector

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例9: Annotate

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [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

示例10: WindowConstruction

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [as 别名]
class WindowConstruction(object):
    ## Shape = (ny,nx)
    def __init__(self,x,y,shape,anomaly,ax,ax2,points2pad):
        self.x = x
        self.y = y
        self.shape = shape
        self.ax = ax
        self.ax2 = ax2
        self.points2pad = points2pad
        self.anomaly = anomaly
        self.dx = (max(x)-min(x))/(self.shape[1]-1)
        self.half_width = (min(self.shape)/16)*self.dx
        self.x_center = None
        self.y_center = None
        self.rect = Rectangle((0,0), 1, 1,fc='None')
        self.x1 = None
        self.y1 = None
        self.x2 = None
        self.y2 = None
        self.shape_window = None
        self.l, = self.ax.plot([self.x_center],[self.y_center],'o')
        self.ax.add_patch(self.rect)
        self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
        self.ax.figure.canvas.mpl_connect('scroll_event', self.on_scroll)
        self.ax.figure.canvas.mpl_connect('key_press_event', self.on_key)
        
        print "\nINSTRUCTIONS:"
        print "Click to select the window center"
        print "Move the center with arrows or click again"
        print "Resize the window with the mouse scroll or with '+' and '-'"
        print "Press 'i' to show information about the window"
        print "Press Enter or Right Click to plot the spectrum of the current window\n"
        
        
    def on_press(self,event):
        if event.inaxes!=self.ax:
            return
        if event.button == 1:
            self.x_center = event.xdata
            self.y_center = event.ydata
            self.x_center, self.y_center = nearest_point(self.x_center,
                                            self.y_center, self.x,self.y)
        elif event.button == 3:
            self.plot_spectrum()
        self.rectangle_construction()
        
        
    def on_scroll(self,event):
        self.half_width += event.step*self.dx
        self.rectangle_construction()
    
    
    def on_key(self,event):
        event_list = ["right","left","up","down"]
        if event.key in event_list:
            if event.key == "right":
                self.x_center += self.dx
            elif event.key == "left":
                self.x_center -= self.dx
            elif event.key == "up":
                self.y_center += self.dx
            elif event.key == "down":
                self.y_center -= self.dx
            self.rectangle_construction()
        if event.key == "enter":
            self.plot_spectrum()
        if event.key == "i":
            print "(x,y)=",(self.x_center,self.y_center),"Width:",self.half_width*2
        if event.key == "+" or event.key == "-":
            if event.key == "+":
                self.half_width += self.dx
            elif event.key == "-":
                self.half_width -= self.dx
            self.rectangle_construction()
            
            
    def rectangle_construction(self):
        self.x1 = self.x_center - self.half_width
        self.x2 = self.x_center + self.half_width
        self.y1 = self.y_center - self.half_width
        self.y2 = self.y_center + self.half_width
        self.shape_window = (2*self.half_width/self.dx+1,
                            2*self.half_width/self.dx+1)
        self.rect.set_width(self.x2 - self.x1)
        self.rect.set_height(self.y2 - self.y1)
        self.rect.set_xy((self.x1, self.y1))
        self.l.set_xdata([self.x_center])
        self.l.set_ydata([self.y_center])
        self.ax.figure.canvas.draw()
        

    def plot_radial_spectrum(self,f,log_spectrum,log_errors):
        self.ax2.cla()
        self.ax2.errorbar(f,log_spectrum,yerr=log_errors,fmt='o')
        self.ax2.set_ylabel(r"$\ln(\Phi_{\Delta T})$")
        self.ax2.set_ylim(-max(abs(log_spectrum)),0.2)
        self.ax2.set_xlim(0,max(f))
        self.ax2.figure.canvas.draw()
    
    
#.........这里部分代码省略.........
开发者ID:santis19,项目名称:tesina-fisica,代码行数:103,代码来源:objects_functions.py

示例11: InteractiveCanvas

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [as 别名]

#.........这里部分代码省略.........

        # Draw extant rectangles if applicable
        if self.mplRectangles:
            self.drawRectangles()

        # Update the figure object/property
        self.fig = plt.gcf()

        self.fig.tight_layout()

    def drawRectangles(self):
        """Adds rectangles to the plot if they are currently stored"""
        # Iterate through the mpl Rectangles to draw them with the proper color
        for i, rectangle in enumerate(self.rectCoordinates):

            color = self.colors[i * 4]
            xy, width, height = rectangle

            rect = Rectangle(
                xy, width, height, alpha=self.alpha, color=color)

            self.ax.add_patch(rect)


    def addPointsAndLine(self, xdata, ydata, color='#003366', draw=True):
        """Adds the points and a line to the figure

        Parameters
        ----------
        xdata: `np.array`
            A flat numpy array of x values for the plot
        ydata: `np.array`
            A flat numpy array of y values for the plot
        color: str
            Hex code or other matplotlib accepted color key for the points/line
        draw: bool
            If True, the plot will be drawn. If False, it will not. Mainly a
            product of the test code

        """
        # Currently ydata is longer than xdata with schlumberger, so handle
        #   that if it makes it this far into the program
        if len(xdata) != len(ydata):
            if len(ydata) > len(xdata):
                xdata = xdata[:len(ydata)]
            else:
                ydata = ydata[:len(xdata)]

        # log/log plot of x and y data
        plt.loglog(
            xdata, ydata, linestyle=self.linestyle,
            marker=self.marker, color=color)

        # Draw the updates
        if draw:
            self.fig.tight_layout()
            self.ax.figure.canvas.draw()


    def onPress(self, event):
        """Handle mouse press events on the matplotlib figure cavas

        Parameters
        ----------
        event: matplotlib.event
            The matplotlib event definition. In this case, a mouse click.

        """
        self.x0 = event.xdata
        self.y0 = event.ydata


    def onRelease(self, event):
        """Handles release of mouse button events on the matplotlib canvas

        Parameters
        ----------
        event: matplotlib.event
            The matplotlib event definition. In this case, a mouse release.

        """
        try:
            self.x1 = event.xdata
            self.y1 = event.ydata

            # Create a rectangle on the plot
            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()

            # Store and return the rectangle attributes as a tuple
            self.rectxy = (
                self.rect.get_xy(), self.rect._width, self.rect._height)

            return self.rectxy

        except TypeError:
            pass
开发者ID:ajoros,项目名称:ves,代码行数:104,代码来源:figures.py

示例12: display_bx

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [as 别名]
  def display_bx():
      bx[0].cla()
      bx[1].cla()
      bx[3].cla()
      bx[4].cla()
      bx[5].cla()
      bx[0].text(20, 0.0, r'g-r', fontsize=15)
      bx[1].text(20, 0.0, r'g-i', fontsize=15)
      bx[3].text(20, 2, r'r-i', fontsize=15)
      bx[4].text(20, 2, r'i-z', fontsize=15)
      bx[5].text(20, 2, r'r-z', fontsize=15)
      bx[0].scatter(self.gr_mag_all, self.gr_color_all,color="black", marker='.',s=1)
      bx[1].scatter(self.gi_mag_all, self.gi_color_all,color="black", marker='.',s=1)
      bx[3].scatter(self.ri_mag_all, self.ri_color_all,color="black", marker='.',s=1)
 	    bx[4].scatter(self.iz_mag_all, self.iz_color_all,color="black", marker='.',s=1)
      bx[5].scatter(self.rz_mag_all, self.rz_color_all,color="black", marker='.',s=1)
 	    if len(self.ra) > 1:
         bx[0].scatter(self.r_mag,self.gr_color,marker='o',s=40,color="blue")
         bx[1].scatter(self.i_mag,self.gi_color,marker='o',s=40,color="green")
         bx[3].scatter(self.r_mag,self.ri_color,marker='o',s=40,color="orange")
         bx[4].scatter(self.i_mag,self.iz_color,marker='o',s=40,color="red")
         bx[5].scatter(self.i_mag,self.rz_color,marker='o',s=40,color="magenta")    
      if len(self.zra) > 1:
         bx[0].scatter(self.z_gr_mag,self.z_gr_color,color="cyan",marker='s',s=5)
         bx[1].scatter(self.z_gi_mag,self.z_gi_color,color="cyan",marker='s',s=5)
         bx[3].scatter(self.z_ri_mag,self.z_ri_color,color="cyan",marker='s',s=5)
         bx[4].scatter(self.z_iz_mag,self.z_iz_color,color="cyan",marker='s',s=5)
         bx[5].scatter(self.z_rz_mag,self.z_rz_color,color="cyan",marker='s',s=5)
      if len(self.bcg_ra>1):
         bx[0].scatter(self.bcg_r_mag,self.bcg_gr_color,color="red",marker=(5, 0),s=250, alpha=0.2)
         bx[1].scatter(self.bcg_i_mag,self.bcg_gi_color,color="red",marker=(5, 0),s=250, alpha=0.2)
         bx[3].scatter(self.bcg_r_mag,self.bcg_ri_color,color="red",marker=(5, 0),s=250, alpha=0.2)
         bx[4].scatter(self.bcg_i_mag,self.bcg_iz_color,color="red",marker=(5, 0),s=250, alpha=0.2)
         bx[5].scatter(self.bcg_i_mag,self.bcg_rz_color,color="red",marker=(5, 0),s=250, alpha=0.2)
      if self.temp_gr_color !=-100:
         bx[0].scatter(self.temp_r_mag, self.temp_gr_color, color="black", marker=(5, 2), s=250, alpha=0.4)
         bx[1].scatter(self.temp_i_mag, self.temp_gi_color, color="black", marker=(5, 2), s=250, alpha=0.4)
         bx[3].scatter(self.temp_r_mag, self.temp_ri_color, color="black", marker=(5, 2), s=250, alpha=0.4)
         bx[4].scatter(self.temp_i_mag, self.temp_iz_color, color="black", marker=(5, 2), s=250, alpha=0.4)
         bx[5].scatter(self.temp_i_mag, self.temp_rz_color, color="black", marker=(5, 2), s=250, alpha=0.4)
      if (self.gr_xbot != 0):
         rect = Rectangle( ( 0,0 ), 1, 1, alpha = 0.2, ec = "gray", fc = "CornflowerBlue", visible = True, axes=bx[0])
         rect.set_width(self.gr_xtop - self.gr_xbot)
         rect.set_height(self.gr_ytop - self.gr_ybot)
         rect.set_xy((self.gr_xbot, self.gr_ybot))
         bx[0].add_patch(rect)
      if (self.gi_xbot != 0):
         rect = Rectangle( ( 0,0 ), 1, 1, alpha = 0.2, ec = "gray", fc = "CornflowerBlue", visible = True, axes=bx[1])
         rect.set_width(self.gi_xtop - self.gi_xbot)
         rect.set_height(self.gi_ytop - self.gi_ybot)
         rect.set_xy((self.gi_xbot, self.gi_ybot))
         bx[1].add_patch(rect)
      if (self.ri_xbot != 0):
         rect = Rectangle( ( 0,0 ), 1, 1, alpha = 0.2, ec = "gray", fc = "CornflowerBlue", visible = True, axes=bx[3])
         rect.set_width(self.ri_xtop - self.ri_xbot)
         rect.set_height(self.ri_ytop - self.ri_ybot)
         rect.set_xy((self.ri_xbot, self.ri_ybot))
         bx[3].add_patch(rect)
      if (self.iz_xbot != 0):
         rect = Rectangle( ( 0,0 ), 1, 1, alpha = 0.2, ec = "gray", fc = "CornflowerBlue", visible = True, axes=bx[4])
         rect.set_width(self.iz_xtop - self.iz_xbot)
         rect.set_height(self.iz_ytop - self.iz_ybot)
         rect.set_xy((self.iz_xbot, self.iz_ybot))
         bx[4].add_patch(rect)
      if (self.rz_xbot != 0):
         rect = Rectangle( ( 0,0 ), 1, 1, alpha = 0.2, ec = "gray", fc = "CornflowerBlue", visible = True, axes=bx[5])
         rect.set_width(self.rz_xtop - self.rz_xbot)
         rect.set_height(self.rz_ytop - self.rz_ybot)
         rect.set_xy((self.rz_xbot, self.rz_ybot))
         bx[5].add_patch(rect)  
      bx.set_xlim(16, 24)
      bx.set_ylim(-0.2, 3.5)
      bx.axes_llc.set_xlabel("magnitude")
      bx.axes_llc.set_ylabel("color")
      fig2.suptitle('Measured Redshift = '+'{: .3f}'.format(xcs_z), fontsize=20)
      fig2.canvas.draw()  
开发者ID:rachelp,项目名称:des_cmr,代码行数:78,代码来源:bcg_image2.py

示例13: ImagePanel

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [as 别名]

#.........这里部分代码省略.........
        self.imgToolbar= []
        for v in set:
            text, image, relief, command, side = v.split('$')
            self.imgToolbar.append(tk.PhotoImage(file=image+'.gif'))
            button = tk.Button(toolbar_frame, image=self.imgToolbar[-1], text=text, relief=eval(relief), command=eval(command))
            button.pack(side=tk.LEFT, fill=tk.BOTH, expand=0)
        return toolbar_frame

    def drawRectangle(self):
        print('Draw rectangle!')
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        self.xp0 = None
        self.yp0 = None
        self.xp1 = None
        self.yp1 = None
        self.rectangle = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
        self.subplot.add_patch(self.rectangle)
        self.ispressed = False
        self.bpe = self.canvas.mpl_connect('button_press_event', self.drawRectangle_onPress)
        self.bre = self.canvas.mpl_connect('button_release_event', self.drawRectangle_onRelease)
        self.mne = self.canvas.mpl_connect('motion_notify_event', self.drawRectangle_onMotion)

    def drawRectangle_onPress(self, event):
        self.xp0 = event.x
        self.yp0 = event.y
        self.x0 = event.xdata
        self.y0 = event.ydata
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rectangle.set_width(self.x1-self.x0)
        self.rectangle.set_xy((self.x0, self.y0))
        self.rectangle.set_linestyle('dashed')
        self.canvas.draw()
        self.ispressed = True


    def drawRectangle_onRelease(self, event):
        self.xp1 = event.x
        self.yp1 = event.y
        self.x1 = event.xdata
        self.y1 = event.ydata
        self.rectangle.set_width(self.x1-self.x0)
        self.rectangle.set_height(self.y1-self.y0)
        self.rectangle.set_xy((self.x0, self.y0))
        self.rectangle.set_linestyle('solid')
        self.canvas.draw()
        self.ispressed = False
        self.canvas.mpl_disconnect(self.bpe)
        self.canvas.mpl_disconnect(self.bre)
        self.canvas.mpl_disconnect(self.mne)
        print(self.xp0, self.yp0, self.xp1, self.yp1)
        self.inform('<DrawRectangle>')
        return (self.xp0, self.yp0, self.xp1, self.yp1)

    def getRectanglePoints(self):
        return (self.xp0, self.yp0, self.xp1, self.yp1)

    def drawRectangle_onMotion(self, event):
        if self.ispressed is True:
            self.x1 = event.xdata
            self.y1 = event.ydata
            self.rectangle.set_width(self.x1-self.x0)
            self.rectangle.set_height(self.y1-self.y0)
开发者ID:rpolanek,项目名称:gellies,代码行数:70,代码来源:panels.py

示例14: MplRectangularROI

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

    """
    A subclass of RectangularROI that also renders the ROI to a plot

    *Attributes*:

        plot_opts:

                   Dictionary instance
                   A dictionary of plot keywords that are passed to
                   the patch representing the ROI. These control
                   the visual properties of the ROI
    """

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

        AbstractMplRoi.__init__(self, axes)

        self._xi = None
        self._yi = None

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

        self._patch = Rectangle((0., 0.), 1., 1.)
        self._patch.set_zorder(100)
        self._setup_patch()

    def _setup_patch(self):
        self._axes.add_patch(self._patch)
        self._patch.set_visible(False)

        self._sync_patch()

    def _roi_factory(self):
        return RectangularROI()

    def start_selection(self, event):

        if event.inaxes != self._axes:
            return False

        if event.key == SCRUBBING_KEY:
            if not self._roi.defined():
                return False
            elif not self._roi.contains(event.xdata, event.ydata):
                return False

        self._roi_store()
        self._xi = event.xdata
        self._yi = event.ydata

        if event.key == SCRUBBING_KEY:
            self._scrubbing = True
            self._cx, self._cy = self._roi.center()
        else:
            self.reset()
            self._roi.update_limits(event.xdata, event.ydata,
                                    event.xdata, event.ydata)

        self._mid_selection = True
        self._sync_patch()

    def update_selection(self, event):

        if not self._mid_selection or event.inaxes != self._axes:
            return False

        if event.key == SCRUBBING_KEY:
            if not self._roi.defined():
                return False

        if self._scrubbing:
            self._roi.move_to(self._cx + event.xdata - self._xi,
                              self._cy + event.ydata - self._yi)
        else:
            self._roi.update_limits(min(event.xdata, self._xi),
                                    min(event.ydata, self._yi),
                                    max(event.xdata, self._xi),
                                    max(event.ydata, self._yi))
        self._sync_patch()

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

    def _sync_patch(self):
        if self._roi.defined():
            corner = self._roi.corner()
            width = self._roi.width()
            height = self._roi.height()
            self._patch.set_xy(corner)
            self._patch.set_width(width)
            self._patch.set_height(height)
#.........这里部分代码省略.........
开发者ID:saimn,项目名称:glue,代码行数:103,代码来源:roi.py

示例15: PlotFrame

# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_xy [as 别名]
class PlotFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, None, size=(300,500), pos=(650, 50), title='Plot Frame')
        self.parent = parent
        
        # initialize plot        
        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)        
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        
        # Connect the mouse events to their relevant callbacks
        self.canvas.mpl_connect('button_press_event', self._onPress)
        self.canvas.mpl_connect('button_release_event', self._onRelease)
        self.canvas.mpl_connect('motion_notify_event', self._onMotion)
        
        self.pressed = False
        
        # Initialise the rectangle
        self.rect = Rectangle((0,0), 1, 1, facecolor='None', visible=False,
                                  edgecolor='k', linestyle='dashed')
        self.x0 = 0#None
        self.y0 = 0#None
        self.x1 = 0#None
        self.y1 = 0#None
        self.axes.add_patch(self.rect)
        
        self.Fit()
        
    def _onPress(self, event):
        ''' Callback to handle the mouse being clicked and held over the canvas'''
        print "onPress"
        # Check the mouse press was actually on the canvas
        if event.xdata is not None and event.ydata is not None:
            print "In press event data"
            # Upon initial press of the mouse record the origin and record the mouse as pressed
            self.pressed = True
            self.rect.set_visible = True
            self.x0 = event.xdata
            self.y0 = event.ydata
            
            # Set the width and height and draw the rectangle
            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.axes.add_patch(self.rect)
            self.canvas.draw()


    def _onRelease(self, event):
        '''Callback to handle the mouse being released over the canvas'''
        print "onRelease"
        # Check that the mouse was actually pressed on the canvas to begin with and this isn't a rouge mouse 
        # release event that started somewhere else
        if self.pressed:

            # Upon release draw the rectangle as a solid rectangle
            self.pressed = False

            # Check the mouse was released on the canvas, and if it wasn't then just leave the width and 
            # height as the last values set by the motion event
            if event.xdata is not None and event.ydata is not None:
                self.x1 = event.xdata
                self.y1 = event.ydata

            # Set the width and height and origin of the bounding rectangle
            self.boundingRectWidth =  self.x1 - self.x0
            self.boundingRectHeight =  self.y1 - self.y0
            self.bouningRectOrigin = (self.x0, self.y0)

            # Draw the bounding rectangle
            self.rect.set_width(self.boundingRectWidth)
            self.rect.set_height(self.boundingRectHeight)
            self.rect.set_xy((self.x0, self.y0))
            
            # set zoom
            xmin = min([self.x0, self.x1])
            xmax = max([self.x0, self.x1])
            ymin = min([self.y0, self.y1])
            ymax = max([self.y0, self.y1])
            self.figure.axes[0].axis([xmin, xmax, ymin, ymax])
            self.rect.set_visible = False

            self.canvas.draw()


    def _onMotion(self, event):
        '''Callback to handle the motion event created by the mouse moving over the canvas'''
        #print "onMotion"
        # If the mouse has been pressed draw an updated rectangle when the mouse is moved so 
        # the user can see what the current selection is
        if self.pressed:

            # Check the mouse was released on the canvas, and if it wasn't then just leave the width and 
            # height as the last values set by the motion event
            if event.xdata is not None and event.ydata is not None:
                self.x1 = event.xdata
                self.y1 = event.ydata
#.........这里部分代码省略.........
开发者ID:scottyuecao,项目名称:RIXS-utilities,代码行数:103,代码来源:plotter_aligner.py


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