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


Python Circle.set_radius方法代码示例

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


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

示例1: Annotate

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_radius [as 别名]
class Annotate(object):
    def __init__(self):
        self.ax = plt.gca()
        # self.rect = Rectangle((0,0), 1, 1)
        self.circ = Circle((0,0), 1, alpha=0.1)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None
        # self.ax.add_patch(self.rect)
        self.ax.add_patch(self.circ)
        self.press = None
        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):
        print 'press'
        self.press = 1
        self.x0 = event.xdata
        self.y0 = event.ydata

    def on_motion(self, event):
        if self.press is None:
            return
        self.x1 = event.xdata
        self.y1 = event.ydata
        radius = ((self.x1 - self.x0)**2 + (self.y1 - self.y0)**2)**0.5
        self.circ.set_radius(radius)
        self.circ.center = 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.ax.figure.canvas.draw()

    def on_release(self, event):
        print 'release'
        self.press = None
        self.x1 = event.xdata
        self.y1 = event.ydata
        radius = ((self.x1 - self.x0) ** 2 + (self.y1 - self.y0) ** 2) ** 0.5
        self.circ.set_radius(radius)
        self.circ.center = 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.ax.figure.canvas.draw()
开发者ID:drolmaeye,项目名称:Diptera,代码行数:49,代码来源:drag_rectangle.py

示例2: Annotate

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

#.........这里部分代码省略.........
        
        if cloud.shape[1] == 6:
            self.cloud = cloud
        else:
            self.cloud = np.c_[cloud[:,:3], np.tile(self.unlabeled_color, (cloud.shape[0],1))]
        
        if z_color:
            z_min = self.cloud[:,2].min()
            z_max = self.cloud[:,2].max()
            self.z_color = np.empty((len(self.cloud),3))
            for i in range(len(self.cloud)):
                f = (self.cloud[i,2] - z_min) / (z_max - z_min)
                self.z_color[i,:] = np.array(colorsys.hsv_to_rgb(f,1,1))
        else:
            self.z_color = None
        self.scatters = []
        self.rescatter_cloud()
        self.ax.autoscale(False)
        
        if self.selection_shape == 'rectangle' or self.selection_shape == 'square':
            self.rect = Rectangle((0,0), 0, 0, facecolor='None', edgecolor='green', linestyle='dashed')
            self.ax.add_patch(self.rect)
        elif self.selection_shape == 'circle':
            self.circle = Circle((0,0), 0, facecolor='None', edgecolor='green', linestyle='dashed')
            self.ax.add_patch(self.circle)
        self.x0 = None
        self.y0 = None
        self.x1 = None
        self.y1 = None

        self.fig.canvas.mpl_connect('button_press_event', self.on_press)
        self.fig.canvas.mpl_connect('button_release_event', self.on_release)
        self.motion_notify_cid = None
        self.fig.canvas.mpl_connect('key_press_event', self.on_key)

        plt.show()
    
    def rescatter_cloud(self):
        for scatter in self.scatters:
            scatter.remove()
        self.scatters = []
        if self.z_color is not None:
            ul_inds = np.absolute((self.cloud[:,3:] - self.unlabeled_color)).sum(axis=1) == 0 # unlabeled inds
            self.scatters.append(plt.scatter(self.cloud[ul_inds,0], self.cloud[ul_inds,1], c=self.z_color[ul_inds,:], edgecolors=self.z_color[ul_inds,:], marker=',', s=5))
            self.scatters.append(plt.scatter(self.cloud[~ul_inds,0], self.cloud[~ul_inds,1], c=self.cloud[~ul_inds,3:], edgecolors=self.cloud[~ul_inds,3:], marker='o', s=20))
        else:
            self.scatters.append(plt.scatter(self.cloud[:,0], self.cloud[:,1], c=self.cloud[:,3:], edgecolors=self.cloud[:,3:], marker=',', s=5))
    
    def on_press(self, event):
        if event.xdata < self.ax.get_xlim()[0] or event.xdata > self.ax.get_xlim()[1] or \
            event.ydata < self.ax.get_ylim()[0] or event.ydata > self.ax.get_ylim()[1]:
            return
        self.x0 = event.xdata
        self.y0 = event.ydata
        self.motion_notify_cid = self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion)

    def on_release(self, event):
        if self.motion_notify_cid:
            self.fig.canvas.mpl_disconnect(self.motion_notify_cid)
            self.motion_notify_cid = None
            if self.selection_shape == 'rectangle' or self.selection_shape == 'square':
                x0 = min(self.x0, self.x1)
                x1 = max(self.x0, self.x1)
                y0 = min(self.y0, self.y1)
                y1 = max(self.y0, self.y1)
                inside_rect_inds = (x0 <= self.cloud[:,0]) * (self.cloud[:,0] <= x1) * (y0 <= self.cloud[:,1]) * (self.cloud[:,1] <= y1)
                num_pts_inside_rect = inside_rect_inds.sum()
                self.cloud[inside_rect_inds,3:] = np.tile(self.labeled_color, (num_pts_inside_rect,1))
            elif self.selection_shape == 'circle':
                inside_circle_inds = np.apply_along_axis(np.linalg.norm, 1, self.cloud[:,:2] - np.array(self.circle.center)) <= self.circle.get_radius()
                num_pts_inside_circle = inside_circle_inds.sum()
                self.cloud[inside_circle_inds,3:] = np.tile(self.labeled_color, (num_pts_inside_circle,1))
            self.rescatter_cloud()
            plt.draw()
    
    def on_motion(self, event):
        if event.xdata < self.ax.get_xlim()[0] or event.xdata > self.ax.get_xlim()[1] or \
            event.ydata < self.ax.get_ylim()[0] or event.ydata > self.ax.get_ylim()[1]:
            return
        if self.selection_shape == 'rectangle':
            self.x1 = event.xdata
            self.y1 = event.ydata
        elif self.selection_shape == 'circle' or self.selection_shape == 'square':
            side = max(abs(event.xdata - self.x0), abs(event.ydata - self.y0))
            self.x1 = self.x0 + np.sign(event.xdata - self.x0) * side
            self.y1 = self.y0 + np.sign(event.ydata - self.y0) * side
        if self.selection_shape == 'rectangle' or self.selection_shape == 'square':
            self.rect.set_width(self.x1 - self.x0)
            self.rect.set_height(self.y1 - self.y0)
            self.rect.set_xy((self.x0, self.y0))
        elif self.selection_shape == 'circle':
            self.circle.center = ((self.x1 + self.x0)/2.0, (self.y0 + self.y1)/2.0)
            self.circle.set_radius(side/2.0)
        plt.draw()
    
    def on_key(self, event):
        if event.key == 'q':
            sys.exit(0)
        if event.key == 'd':
            plt.close(self.fig)
开发者ID:shhuang,项目名称:jointopt-lfd,代码行数:104,代码来源:label_clouds.py

示例3: EnvironmentReader

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_radius [as 别名]
class EnvironmentReader(Reader):
    def __init__(self, vl, room_shape, start_iter):
        super(EnvironmentReader,self).__init__(win_size=[700,700],
                                               win_loc=pos,
                                               title='Environment')
        self.vl = vl
        self.cur_iter = start_iter
        
        self.cur_i = 0
        self.max_iter = np.max(vl['Iter num'])
        self.maxx = room_shape[0][1]
        self.maxy = room_shape[1][1]
        self.cntr_x = np.mean(room_shape[0])
        self.cntr_y = np.mean(room_shape[1])
        
        self.x_hist = []; self.y_hist = []
        
        self.canvas.mpl_connect('resize_event',lambda x: self.update_background())
        
        self.pos, = self.ax.plot([],[],color='g',animated=True)
        self.vel = Arrow([0,0],[1,0],arrowstyle='-|>, head_length=3, head_width=3',
                         animated=True, linewidth=4)
        self.ax.add_patch(self.vel)
        #self.radius, = self.ax.plot([],[],color='r',animated=True)
        self.clockcounter = self.ax.text(self.maxx,room_shape[1][0],
                                         '',ha='right',size='large',
                                         animated=True)
        self.iters = self.ax.text(self.maxx-1, room_shape[1][0]+3,
                                  '',ha='right',animated=True)
        self.target = Circle([0,0],0,animated=True,color='r')
        self.target.set_radius(11)
        self.ax.add_artist(self.target)
        
        self.ax.set_xlim(room_shape[0])
        self.ax.set_ylim(room_shape[1])
        
        self.draw_plc_flds()
        
        self.draw_HMM_sectors()
        self.predicted_counter = self.ax.text(self.maxx,room_shape[1][0]+10,'',
                                              ha='right',size='large',animated=True)
        self.prediction_hist = None
        #self.cur_sec = Rectangle([0,0],self.HMM.dx,self.HMM.dy,fill=True,
        #                         color='k',animated=True)
        #self.ax_env.add_patch(self.cur_sec)
        
        self.canvas.draw()
        
    def read(self, iteration=None):
        ''' Return the environment data corresponding to
            the next iteration.
            
            Note that 0 or multiple data points can be
            associated with a single iteration number.
            
            All of the environment data before self.cur_i
            has already been recorded.'''
        if iteration is not None: self.cur_iter = iteration
        try:
            cur_j = 1+self.cur_i+ np.nonzero(self.vl['Iter num'][self.cur_i:] == self.cur_iter)[0][-1]
        except:
            # There is no iteration with that value
            self.cur_iter += 1
            return [np.NAN, np.NAN, np.NAN, np.NAN]
        cur_x = self.vl['xs'][self.cur_i:cur_j]
        cur_y = self.vl['ys'][self.cur_i:cur_j]
        cur_vx = self.vl['vxs'][self.cur_i:cur_j]
        cur_vy = self.vl['vys'][self.cur_i:cur_j]
        self.cur_iter += 1
        self.cur_i = cur_j

        return (cur_x, cur_y, cur_vx, cur_vy)
    
    def draw_HMM_sectors(self):
        return
        for i in range(self.HMM.cll_p_sd):
            curx = self.HMM.xrange[0]+i*self.HMM.dx
            cury = self.HMM.yrange[0]+i*self.HMM.dy
            self.ax_env.plot([curx,curx],[0,self.maxy],'k')
            self.ax_env.plot([0,self.maxx],[cury,cury], 'k')

        
    def draw_plc_flds(self):
        return
        clrs = ['b','g']
        legend_widgets = []
        for i, plc_flds in zip(range(len(self.WR.contexts)),self.WR.contexts.values()):
            added = False
            for plc_fld in plc_flds:
                circ = Circle([plc_fld.x,plc_fld.y], plc_fld.r, color=clrs[i])
                self.ax_env.add_patch(circ)
                
                if not added:
                    legend_widgets.append(circ)
                    added=True
        self.ax.legend(legend_widgets, ('counterclockwise','clockwise'),'lower right')
    
    def draw(self, xs,ys,vxs,vys):
        ''' Display the environment data to the window.
        
#.........这里部分代码省略.........
开发者ID:joel-shor,项目名称:Context-Classifier,代码行数:103,代码来源:EnvironmentReader.py


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