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


Python Path.circle方法代码示例

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


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

示例1: nearest_point

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import circle [as 别名]
 def nearest_point(self, lon, lat, lons, lats, length=0.06):  #0.3/5==0.06
     '''Find the nearest point to (lon,lat) from (lons,lats),
        return the nearest-point (lon,lat)
        author: Bingwei'''
     p = Path.circle((lon,lat),radius=length)
     #numpy.vstack(tup):Stack arrays in sequence vertically
     points = np.vstack((lons.flatten(),lats.flatten())).T  
     
     insidep = []
     #collect the points included in Path.
     for i in xrange(len(points)):
         if p.contains_point(points[i]):# .contains_point return 0 or 1
             insidep.append(points[i])  
     # if insidep is null, there is no point in the path.
     if not insidep:
         #print 'This point out of the model area or hits the land.'
         raise Exception()
     #calculate the distance of every points in insidep to (lon,lat)
     distancelist = []
     for i in insidep:
         ss=math.sqrt((lon-i[0])**2+(lat-i[1])**2)
         distancelist.append(ss)
     # find index of the min-distance
     mindex = np.argmin(distancelist)
     # location the point
     lonp = insidep[mindex][0]; latp = insidep[mindex][1]
     
     return lonp,latp
开发者ID:LingBW,项目名称:Web-track_Python,代码行数:30,代码来源:track_functions.py

示例2: shrink_data

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import circle [as 别名]
 def shrink_data(self,lon,lat,lons,lats):
     # ind = argwhere((lonc >= size[0]) & (lonc <= size[1]) & (latc >= size[2]) & (latc <= size[3]))
     lont = []; latt = []
     p = Path.circle((lon,lat),radius=0.6)
     pints = np.vstack((lons.flatten(),lats.flatten())).T
     for i in range(len(pints)):
         if p.contains_point(pints[i]):
             lont.append(pints[i][0])
             latt.append(pints[i][1])
     lonl=np.array(lont); latl=np.array(latt)#'''
     if not lont:
         print 'point position error! shrink_data'
         sys.exit()
     return lonl,latl
开发者ID:LingBW,项目名称:Web-track_Python,代码行数:16,代码来源:track_functions.py

示例3: eline_path

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import circle [as 别名]
 def eline_path(self,lon,lat):
     '''
     When drifter close to boundary(less than 0.1),find one nearest point to drifter from boundary points, 
     then find two nearest boundary points to previous boundary point, create a boundary path using that 
     three boundary points.
     '''
     def boundary_location(locindex,pointt,wl):
         '''
         Return the index of boundary points nearest to 'locindex'.
         '''
         loca = []
         dx = pointt[locindex]; #print 'func',dx 
         for i in dx: # i is a number.
             #print i  
             if i ==0 :
                 continue
             dx1 = pointt[i-1]; #print dx1
             if 0 in dx1:
                 loca.append(i-1)
             else:
                 for j in dx1:
                     if j != locindex+1:
                         if wl[j-1] == 1:
                             loca.append(j-1)
         return loca
     
     p = Path.circle((lon,lat),radius=0.02) #0.06
     dis = []; bps = []; pa = []
     tlons = []; tlats = []; loca = []
     for i in self.b_points:
         if p.contains_point(i):
             bps.append((i[0],i[1]))
             d = math.sqrt((lon-i[0])**2+(lat-i[1])**2)
             dis.append(d)
     bps = np.array(bps)
     if not dis:
         return None
     else:
         #print "Close to boundary."
         dnp = np.array(dis)
         dmin = np.argmin(dnp)
         lonp = bps[dmin][0]; latp = bps[dmin][1]
         index1 = np.where(self.lonc==lonp)
         index2 = np.where(self.latc==latp)
         elementindex = np.intersect1d(index1,index2)[0] # location 753'''
         #print index1,index2,elementindex  
         loc1 = boundary_location(elementindex,self.pointt,self.wl) ; #print 'loc1',loc1
         loca.extend(loc1)
         loca.insert(1,elementindex)               
         for i in range(len(loc1)):
             loc2 = boundary_location(loc1[i],self.pointt,self.wl); #print 'loc2',loc2
             if len(loc2)==1:
                 continue
             for j in loc2:
                 if j != elementindex:
                     if i ==0:
                         loca.insert(0,j)
                     else:
                         loca.append(j)
         
         for i in loca:
             tlons.append(self.lonc[i]); tlats.append(self.latc[i])
                    
         for i in xrange(len(tlons)):
             pa.append((tlons[i],tlats[i]))
         path = Path(pa)#,codes
         return path
开发者ID:LingBW,项目名称:Web-track_Python,代码行数:69,代码来源:track_functions.py

示例4: compress_points

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import circle [as 别名]
def compress_points(points):
    bi, bj, bx, by = get_boundary_intersections(points)

    f = bi == bj
    alone_points = points[bi[f]]
    alone_paths = [Path.circle(xy, 0.5) for xy in alone_points]

    edge_lists = [[] for i in range(len(points))]
    n = 0
    for i, j, x, y in zip(bi, bj, bx, by):
        if i != j:
            edge_lists[j].append((i, x, y))
            n += 1

    print("%s points in total: %s edges, %s alone points" %
          (len(points), n, len(alone_points)))

    def patan2(dy, dx):
        """
        Return pseudo-arctangent of dy/dx such that
            patan2(y1, x1) < patan2(y2, x2)
            if and only if
            atan2(y1, x1) < atan2(y2, x2)
        """
        if dy > 0 and dx > 0:
            return (0, dy - dx)
        elif dy > 0 and dx <= 0:
            return (1, -dy - dx)
        elif dy <= 0 and dx > 0:
            return (2, dx - dy)
        else:
            return (3, dx + dy)

    def shift(u, v):
        if v < u:
            return (v[0] + 4, v[1])
        else:
            return v

    def pop_next(i, ox, oy):
        def local_patan2(y, x):
            return patan2(y - points[i, 1], x - points[i, 0])
        u = local_patan2(oy, ox)
        j = min(range(len(edge_lists[i])),
                key=lambda j: shift(u, local_patan2(edge_lists[i][j][2],
                                                    edge_lists[i][j][1])))
        return edge_lists[i].pop(j)

    paths = []
    # print("<path fill=\"black\" fillrule=\"wind\">")
    while n > 0:
        assert sum(len(e) for e in edge_lists) == n
        i = 0
        while not edge_lists[i]:
            i += 1
        start = i
        j, ox, oy = edge_lists[i].pop(0)
        startx, starty = ox, oy
        ux, uy = ox, oy
        # path = ['%s %s m' % (startx, starty)]
        path_vert_lists = [[[startx, starty]]]
        path_code_lists = [[Path.MOVETO]]

        n -= 1
        while j != start:
            i = j
            j, vx, vy = pop_next(i, ux, uy)
            n -= 1
            # path.append(
            #     '%s 0 0 %s %s %s %s %s a' %
            #     (R, R, points[i, 0], points[i, 1], ox, oy))
            ox, oy = points[i]
            theta1 = np.arctan2(uy - oy, ux - ox)
            theta2 = np.arctan2(vy - oy, vx - ox)
            a = Path.arc(theta1 * 180 / np.pi, theta2 * 180 / np.pi)
            a = a.transformed(Affine2D().scale(0.5).translate(ox, oy))
            path_vert_lists.append(a._vertices[1:])
            path_code_lists.append(a._codes[1:])
            ux, uy = vx, vy
        # path.append(
        #     '%s 0 0 %s %s %s %s %s a' %
        #     (R, R, points[j, 0], points[j, 1], startx, starty))
        ox, oy = points[j]
        theta1 = np.arctan2(uy - oy, ux - ox)
        theta2 = np.arctan2(starty - oy, startx - ox)
        a = Path.arc(theta1 * 180 / np.pi, theta2 * 180 / np.pi)
        a = a.transformed(Affine2D().scale(0.5).translate(ox, oy))
        path_vert_lists.append(a._vertices[1:])
        path_code_lists.append(a._codes[1:])
        # print('\n'.join(path))
        paths.append(
            Path(np.concatenate(path_vert_lists),
                 np.concatenate(path_code_lists).astype(Path.code_type)))
    # print("</path>")
    return Path.make_compound_path(*(alone_paths + paths))
开发者ID:Mortal,项目名称:point-union,代码行数:97,代码来源:point_union.py


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