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


Python Path.contains_point方法代码示例

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


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

示例1: reverse_geocode

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def reverse_geocode(tweet):
	# print index
	# latlong = json.load(tweets)[index]['coordinates']
	latlong = tweet["coordinates"]
	if latlong == [0.0, 0.0]:
		return False
	# latlong.reverse()
	with open('world-countries.json.txt', 'r') as countries_json:
		found_country = None
		countries = json.load(countries_json)['features']
		for country in countries:
			country_name = country['properties']['name']
			if country['geometry']['type'] == 'Polygon':
				country_vertices = country['geometry']['coordinates'][0]
				country_path = Path(country_vertices)
				if country_path.contains_point(latlong):
					found_country = country_name
					break
			if country['geometry']['type'] == 'MultiPolygon':
				country_polygons = country['geometry']['coordinates']
				for polygon in country_polygons:
					country_vertices = polygon[0]
					country_path = Path(country_vertices)
					if country_path.contains_point(latlong):
						found_country = country_name
						break
		if not found_country:
			found_country = False
	return found_country
# with open('Ferguson_tweets.txt', 'r') as tweets:
# 	print reverse_geocode(tweets, 0)
开发者ID:seashark97,项目名称:Sentiment-heat-map-generator,代码行数:33,代码来源:reverse_geocoder.py

示例2: pca_var

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
    def pca_var(sub_dims):
        data = np.array([df[d] for d in sub_dims]).T
        try: pca = PCA(data, standardize=True)
        except: return 0,1,0,1,None,None,None,sub_dims

        classed_points = zip(classes, pca.Y)
        pos = [(it[0], it[1]) for c, it in classed_points if c]
        neg = [(it[0], it[1]) for c, it in classed_points if not c]
        P_hull = [pos[i] for i in ConvexHull(pos).vertices]; P_hull.append(P_hull[0])
        N_hull = [neg[i] for i in ConvexHull(neg).vertices]; N_hull.append(N_hull[0])
        P_hull = np.array(P_hull)
        N_hull = np.array(N_hull)
        P_path = Path(P_hull)
        N_path = Path(N_hull)

        N_sep = 0
        for it in neg:
            if not P_path.contains_point(it):
                N_sep += 1

        P_sep = 0
        for it in pos:
            if not N_path.contains_point(it):
                P_sep += 1

        return N_sep, float(len(neg)), P_sep, float(len(pos)), P_hull, N_hull, pca, sub_dims
开发者ID:qfeys,项目名称:ThrottleControlledAvionics,代码行数:28,代码来源:REN-optimization.py

示例3: contained_in

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def contained_in(lat, lng, bound_coords):
    """
    Returns true if (lat, lng) is contained within the polygon formed by the
    points in bound_coords.
    """
    bound_path = Path(np.array(bound_coords))
    return bound_path.contains_point((lat, lng))
开发者ID:ncanac,项目名称:datasci_course_materials,代码行数:9,代码来源:happiest_state.py

示例4: path_contains_points

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
    def path_contains_points(verts, points):
        p = Path(verts, closed=True)
        result = num.zeros(points.shape[0], dtype=num.bool)
        for i in range(result.size):
            result[i] = p.contains_point(points[i, :])

        return result
开发者ID:hvasbath,项目名称:pyrocko,代码行数:9,代码来源:orthodrome.py

示例5: distribute_pixels

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
 def distribute_pixels(self, edges, length, width):
     corners = self.get_corners()
     reg_path = Path(corners)
     # Get region boundaries.
     bounds = reg_path.get_extents().get_points()
     [[x_min_bound, y_min_bound], [x_max_bound, y_max_bound]] = bounds
     # For cases when the boundary pixels are not integers:
     x_min_bound = floor(x_min_bound)
     y_min_bound = floor(y_min_bound)
     x_max_bound = ceil(x_max_bound)
     y_max_bound = ceil(y_max_bound)
     pixels_in_bins = []
     for x in range(max(0, x_min_bound), min(x_max_bound+1, width)):
         for y in range(max(0, y_min_bound), min(y_max_bound+1, length)):
             if reg_path.contains_point((x, y)):
                 x_nonrotated, y_nonrotated = rotate_point(self.x0, self.y0,
                                                           x - self.x0,
                                                           y - self.y0,
                                                           -self.angle)
                 dist_from_box_bottom = self.height/2. - \
                                        (self.y0 - y_nonrotated)
                 for i, edge in enumerate(edges[1:]):
                     if edge > dist_from_box_bottom:
                         pixels_in_bins.append((y, x, i))
                         break
     return pixels_in_bins
开发者ID:gogrean,项目名称:PyXel,代码行数:28,代码来源:box.py

示例6: onselect

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
 def onselect(self, verts):
     path = Path(verts)
     self.ind = np.nonzero([path.contains_point(xy) for xy in self.xys])[0]
     self.fc[:, -1] = self.alpha_other
     self.fc[self.ind, -1] = 1
     self.collection.set_facecolors(self.fc)
     self.canvas.draw_idle()
开发者ID:fedhere,项目名称:detect120,代码行数:9,代码来源:lassoselect.py

示例7: inpolygon

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def inpolygon(x,y,xp,yp):
  '''
  Points inside polygon test.

  Based on matplotlib nxutils for old matplotlib versions
  http://matplotlib.sourceforge.net/faq/howto_faq.html#test-whether-a-point-is-inside-a-polygon

  Can also use Path.contains_point, for recent versions, or
  the pnpoly extension - point in polyon test - by W R Franklin,
  http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
  '''

  try:
    from matplotlib.nxutils import pnpoly, points_inside_poly
    _use_mpl = 1
  except ImportError:
    from matplotlib.path import Path
    _use_mpl = 2
  except:
    import pnpoly
    _use_mpl = False

  shape=False
  try:
    if x.ndim>1:
      shape=x.shape
      x=x.flat
      y=y.flat
  except: pass

  if _use_mpl==1:
    verts=np.array(zip(xp,yp))
    if isiterable(x,y):
      points=np.array(zip(x,y))
      res=points_inside_poly(points,verts)
    else:
      res=pnpoly(x,y,verts)==1

  elif _use_mpl==2:
    verts=np.array(zip(xp,yp))
    p=Path(verts)
    if not isiterable(x,y): x,y,itr=[x],[y],0
    else: itr=1
    res=[p.contains_point((x[i],y[i]), radius=0.) for i in range(len(x))]
    res=np.asarray(res,'bool')
    if not itr: res=res[0]

  else:
    if not isiterable(x,y): x,y,itr=[x],[y],0
    else: itr=1
    res=np.zeros(len(x))
    res=[pnpoly.pnpoly(x[i],y[i],xp,yp,len(xp)) for i in range(len(x))]
    res=np.asarray(res)==1
    if not itr: res=res[0]

  if not shape is False: res.shape=shape
  return res
开发者ID:moghimis,项目名称:okean,代码行数:59,代码来源:calc.py

示例8: insert_fake_stars

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def insert_fake_stars(d,h,mags,all_poly,WCS,sex,survey="UKIDSS",zp=25.):
    fake_stars = []
    xsize = h['NAXIS1']
    ysize = h['NAXIS2']
    #Insert fake star
    if survey== "UKIDSS":
        size = 11
        sigma = 2.5/2.35
    if survey== "VISTA":
        size = 11
        sigma = 2.5/2.35 #FWHM ~ 2.5 pixels
    if survey == "2MASS":
        size = 5

    for mag in mags:
        flag_in = False
        while flag_in == False:
            poly = all_poly #We now only have one contour
            #for poly in all_poly:
            #print(poly)
            verts = np.array(poly,float)
            #print(verts)
            x = np.random.random_sample()*(xsize-size-6)+(size)
            y = np.random.random_sample()*(ysize-size-6)+(size)
            #print(WCS)
            #print(x,y)

            pixcrd  = np.array([[x,y]], np.float_)
            radec = np.array(WCS.wcs_pix2world(pixcrd,0))
            #print(radec)

            gc = coordinates.ICRS(radec[0][0],radec[0][1], unit=(u.degree, u.degree))
            galcoords = gc.galactic
            #L.append(galcoords.l.degrees)
            #B.append(galcoords.b.degrees)
            path = Path(verts)
            yo = path.contains_point((galcoords.l.degree,galcoords.b.degree))
            #yo = nx.pnpoly(galcoords.l.degrees,galcoords.b.degrees,verts)
            if yo == 1:
            #print(te)
                #print("a star is in the contour")
                flag_in = True
            else:
                pass
                #print("a star is outside the contour")
        magnitude = mag
        #zp = sex.config['MAG_ZEROPOINT']
        #Now we pass in zp instead
        expfactor = (magnitude - zp)/(-2.5)
        counts = math.pow(10.,expfactor)
        g = gauss_kern(size,sigma,counts) #5 is rough guess for FWHM
    #       print d[y-size:y+size+1,x-size:x+size+1].size
    #       print g.size
        d[y-size:y+size+1,x-size:x+size+1] += g #Damn backward numpy arrays
        fake_stars.append((x,y,mag))
    fits.writeto("TestOuput.fits",d,h,clobber=True)
    return(fake_stars)
开发者ID:jfoster17,项目名称:extinction-distances,代码行数:59,代码来源:determine_completeness.py

示例9: Track

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
class Track(object):

    def __init__(self):
        self.inner_path = Path(inner)
        self.outer_path = Path(outer)

        self.lines = list()
        for arr in (inner, outer):
            for i in range(len(arr)-1):
                self.lines.append(self.get_line_from_two_points(arr[i], arr[i+1]))

    def get_line_from_two_points(self, p1, p2):
        pa,pb = (p1,p2) if p1[0]<p2[0] else (p2,p1)
        a = (pb[1]-pa[1])/(pb[0]-pa[0])
        c = pa[1]-a*pa[0]
        return a, c, pa[0], pb[0]

    def contains(self, points, edges):
        res = True
        for name,point in points.items():
            if self.inner_path.contains_point(point):
                res = False
                print("Point {} iside inner track boundary".format(name))
            elif not self.outer_path.contains_point(point):
                res = False
                print("Point {} outside outer track boundary".format(name))

        for name,edge in edges.items():
            p = Path(edge, [Path.MOVETO, Path.LINETO])
            for k,v in (('inner',self.inner_path),('outer',self.outer_path)):
                if v.intersects_path(p, filled=False):
                    res = False
                    print("Edge {} intersects {} track boundary".format(name,k))
        return res

    def plot(self):
        fig, ax = plt.subplots()
        ax.add_patch(PathPatch(self.outer_path, facecolor='k', alpha=0.8))
        ax.add_patch(PathPatch(self.inner_path, facecolor='w', alpha=0.9))
        ax.grid(which='both')
        ax.axis('equal')
        ax.set_ylabel("Y (cm)")
        ax.set_xlabel("X (cm)")
        plt.show()
开发者ID:marjakm,项目名称:common,代码行数:46,代码来源:track.py

示例10: is_supported

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
    def is_supported(self, vertices):
        """
        Checks if a given support triangle contains the center of mass.
        This assumes the robot is not on a slant or hill.
        :param vertices: The transformed vertices as a 3 x 2 numpy matrix.
        :return: True if center of mass is in triangle, else False.
        """

        triangle = Path(vertices)
        return triangle.contains_point(self.com[:2])
开发者ID:bobbyluig,项目名称:Eclipse,代码行数:12,代码来源:main.py

示例11: inpolygon

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def inpolygon(x,y,xp,yp):
  from matplotlib.path import Path
  verts=np.array(zip(xp,yp))
  p=Path(verts)
  if not isiterable(x,y): x,y,itr=[x],[y],0
  else: itr=1
  res=[p.contains_point((x[i],y[i]), radius=0.) for i in range(len(x))]
  res=np.asarray(res,'bool')
  if not itr: res=res[0]
  return res
开发者ID:martalmeida,项目名称:tabs,代码行数:12,代码来源:radar.py

示例12: is_in_sector

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def is_in_sector(sector_coords, point_coords):
    
    codes = [Path.MOVETO]
    for i in range(len(sector_coords)-2):
        codes.append(Path.LINETO)
    codes.append(Path.CLOSEPOLY)

    bbPath = Path(sector_coords, codes)
    
    return bool(bbPath.contains_point(point_coords))
开发者ID:ZeromusSoftware,项目名称:RPi3500,代码行数:12,代码来源:coords_maps_sector.py

示例13: in_rhealpix_image

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def in_rhealpix_image(x, y, north_square=0, south_square=0):
    r"""
    Return True if and only if the point `(x, y)` lies in the image of 
    the rHEALPix projection of the unit sphere.
            
    EXAMPLES::
    
        >>> eps = 0     # Test boundary points.
        >>> north_square, south_square = 0, 0
        >>> rhp = [
        ... (-pi - eps, pi/4 + eps),
        ... (-pi + north_square*pi/2 - eps, pi/4 + eps),
        ... (-pi + north_square*pi/2 - eps, 3*pi/4 + eps),
        ... (-pi + (north_square + 1)*pi/2 + eps, 3*pi/4 + eps),
        ... (-pi + (north_square + 1)*pi/2 + eps, pi/4 + eps),
        ... (pi + eps, pi/4 + eps),
        ... (pi + eps,-pi/4 - eps),
        ... (-pi + (south_square + 1)*pi/2 + eps,-pi/4 - eps),
        ... (-pi + (south_square + 1)*pi/2 + eps,-3*pi/4 - eps),
        ... (-pi + south_square*pi/2 - eps,-3*pi/4 - eps),
        ... (-pi + south_square*pi/2 -eps,-pi/4 - eps),
        ... (-pi - eps,-pi/4 - eps)
        ... ]
        >>> for p in rhp:
        ...     if not in_rhealpix_image(*p):
        ...             print('Fail')
        ... 
        >>> print(in_rhealpix_image(0, 0))
        True
        >>> print(in_rhealpix_image(0, pi/4 + 0.1))
        False
        
    """    
    # matplotlib is a third-party module.
    from matplotlib.path import Path
    
    # Fuzz to slightly expand rHEALPix image so that 
    # points on the boundary count as lying in the image.
    eps = 1e-15
    vertices = [
      (-pi - eps, pi/4 + eps),
      (-pi + north_square*pi/2 - eps, pi/4 + eps),
      (-pi + north_square*pi/2 - eps, 3*pi/4 + eps),
      (-pi + (north_square + 1)*pi/2 + eps, 3*pi/4 + eps),
      (-pi + (north_square + 1)*pi/2 + eps, pi/4 + eps),
      (pi + eps, pi/4 + eps),
      (pi + eps, -pi/4 - eps),
      (-pi + (south_square + 1)*pi/2 + eps, -pi/4 - eps),
      (-pi + (south_square + 1)*pi/2 + eps, -3*pi/4 - eps),
      (-pi + south_square*pi/2 - eps, -3*pi/4 - eps),
      (-pi + south_square*pi/2 -eps, -pi/4 - eps),
      (-pi - eps, -pi/4 - eps)
    ]
    poly = Path(vertices)
    return bool(poly.contains_point([x, y]))    
开发者ID:ANU-Linked-Earth-Data,项目名称:dggs,代码行数:57,代码来源:pj_rhealpix.py

示例14: convert

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def convert(x_prime,y_prime,rad,x_start,y_start):
    for j in range(0,hex_num):
        for i in range (0,hex_num):
            vertex_set = []
            x_center = x_start+(rad*2*i)
            y_center = y_start+(rad*math.sqrt(3)*j)
            for k in range(0,6):
                vertex_set.append([x_center+rad*math.cos((2*math.pi*k)/6),y_center+rad*math.sin((2*math.pi*k)/6)])
            vertex_path = Path(vertex_set)
            result = vertex_path.contains_point([x_prime,y_prime],radius=0.1)
            if (result==1):
                return x_prime, y_prime, (j, i)
开发者ID:sk779,项目名称:SeniorResearchRep,代码行数:14,代码来源:FinalHeatmapCode_VaryHex.py

示例15: polyCluster

# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_point [as 别名]
def polyCluster(jumps, bisectingSlopes):
	cluster = -1*np.ones(len(jumps))
	codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
	vertices = polygonVertices(bisectingSlopes)
	nClusters = len(bisectingSlopes)+1
	for iv, v in enumerate(vertices):
		poly = Path(v, codes, closed = True)
		for ij, j in enumerate(jumps):
			if poly.contains_point(j)==1:
				cluster[ij] = iv
	
	return cluster
开发者ID:mdornfe1,项目名称:vocalization_analysis,代码行数:14,代码来源:cluster_slider.py


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