本文整理汇总了Python中matplotlib.path.Path.contains_points方法的典型用法代码示例。如果您正苦于以下问题:Python Path.contains_points方法的具体用法?Python Path.contains_points怎么用?Python Path.contains_points使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.path.Path
的用法示例。
在下文中一共展示了Path.contains_points方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processPolygon
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def processPolygon(polygon, rows, columns, mode):
"""
Finds the points within a particular polygon
"""
length = len(polygon)
polygon.append((0.0, 0.0))
codes = [Path.MOVETO]
for index in range(length - 1):
codes.append(Path.LINETO)
codes.append(Path.CLOSEPOLY)
path = Path(polygon, codes)
points = []
if mode == 'V':
for index in range(rows):
row = [(x, index) for x in range(columns)]
check = path.contains_points(row)
temp_points = ([row[i] for i, j in enumerate(check) if j == True and not contains(row[i], polygon)])
if (len(temp_points) > 0):
points.append(temp_points)
else:
for index in range(columns):
col = [(index, x) for x in range(rows)]
check = path.contains_points(col)
temp_points = ([col[i] for i, j in enumerate(check) if j == True and not contains(col[i], polygon)])
if (len(temp_points) > 0):
points.append(temp_points)
return points
示例2: selectArea
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def selectArea(self, ptlist, latlon=False, reduced=None):
"""Select an area of the grid.
Parameters
----------
ptlist : list
latlon : bool
reduced : int
The amount by which the index array should be short (i.e., 1 for
basic difference, 2 for center difference).
"""
ptlist = np.asarray(ptlist)
if latlon:
ptlist[:,0], ptlist[:,1] = self.basemap(ptlist[:,0], ptlist[:,1])
# create the polygon
path = Path(ptlist)
if reduced is not None:
X, Y = np.meshgrid(self.x[:-reduced], self.y[:-reduced])
areaind = path.contains_points(zip(X.flatten(), Y.flatten()))
areaind = areaind.reshape((self.shape[0]-reduced,
self.shape[1]-reduced))
else:
X, Y = np.meshgrid(self.x, self.y)
areaind = path.contains_points(zip(X.flatten(), Y.flatten()))
areaind = areaind.reshape(self.shape)
# return array indices
return areaind
示例3: number_of_images
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def number_of_images(self, sourceposition):
rc=self.radial_caustic()
tc=self.tangential_caustic()
if usePath:
# New Matplotlib:
rc=Path(rc)
tc=Path(tc)
if rc.contains_points(np.atleast_2d(sourceposition))[0]:
if tc.contains_points(np.atleast_2d(sourceposition))[0]:
return 4
return 2
if tc.contains_points(np.atleast_2d(sourceposition))[0]:
return 3
else:
# Old Matplotlib:
if nxutils.points_inside_poly(np.atleast_2d(sourceposition),rc)[0]:
if nxutils.points_inside_poly(np.atleast_2d(sourceposition),tc)[0]:
return 4
return 2
if nxutils.points_inside_poly(np.atleast_2d(sourceposition),tc)[0]:
return 3
return 1
示例4: _gating
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def _gating(self,DF_array_data,x_ax,y_ax,coords):
#np.ones(DF_array_data.shape[0],dtype=bool)
gate=Path(coords,closed=True)
projection=np.array(DF_array_data[[x_ax,y_ax]])
index=gate.contains_points(projection)
return index
示例5: _endGate
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def _endGate(self, event):
#draw gate rectangle
start_x = self.start_x if self.start_x < event.xdata else event.xdata
start_y = self.start_y if self.start_y < event.ydata else event.ydata
width = np.absolute(event.xdata-self.start_x)
height = np.absolute(event.ydata-self.start_y)
rect = Rectangle((start_x, start_y), width, height,
fill=False, ec='black', alpha=1, lw=2)
self.ax.add_patch(rect)
self.canvas.draw()
#disable mouse events
self.canvas.mpl_disconnect(self.buttonPress)
self.canvas.mpl_disconnect(self.buttonRelease)
self.canvas.get_tk_widget().config(cursor='arrow')
#save cell gate
gate = Path([[start_x, start_y],
[start_x + width, start_y],
[start_x + width, start_y + height],
[start_x, start_y + height],
[start_x, start_y]])
gated_cells = self.scdata.tsne.index[gate.contains_points(self.scdata.tsne)]
self.gates[self.gateName.get()] = gated_cells
#replot tSNE w gate colored
self.fig.clf()
plt.scatter(self.scdata.tsne['x'], self.scdata.tsne['y'], s=10, edgecolors='none', color='lightgrey')
plt.scatter(self.scdata.tsne.ix[gated_cells, 'x'], self.scdata.tsne.ix[gated_cells, 'y'], s=10, edgecolors='none')
self.canvas.draw()
self.setGateButton.config(state='disabled')
self.visMenu.entryconfig(6, state='disabled')
示例6: Ablate_outside_area
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def Ablate_outside_area(n_pixels, contour_coords):
''' Function takes points from contour and returns list of coordinates
lying outside of the contour - to be used to ablate image '''
#Search points outside and black them out:
all_points = []
for i in range(n_pixels):
for j in range(n_pixels):
all_points.append([i,j])
all_points = np.array(all_points)
vertixes = np.array(contour_coords)
vertixes_path = Path(vertixes)
mask = vertixes_path.contains_points(all_points)
ablate_coords=[]
counter=0
for i in range(n_pixels):
for j in range(n_pixels):
if mask[counter] == False:
#images_processed[100][i][j]=0
ablate_coords.append([i,j])
counter+=1
return ablate_coords
示例7: estimate_mean_extinction
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def estimate_mean_extinction(self, poly):
"""Estimate the mean extinction Av in within a footprint.
Parameters
----------
poly : ndarray
The RA,Dec polygon (a rectangle) defining the footprint.
"""
sigma_dust = self._f[0].data
ny, nx = sigma_dust.shape
# Make a coordinate grid out of RA, Dec across the dust map
y_image, x_image = np.mgrid[0:ny, 0:nx]
y = y_image.reshape(nx * ny)
x = x_image.reshape(nx * ny)
ra, dec = self._wcs.all_pix2world(x, y, 0)
points = np.vstack((ra, dec)).T
# Find all pixels in the footprint
path = Path(poly, closed=False)
in_poly = path.contains_points(points)
s = np.where(in_poly)[0]
dust_pixels = sigma_dust[y[s], x[s]]
mean = np.nanmean(dust_pixels)
# Estimate Av from the Lewis et al attenuation law
return 10. ** (-5.4) * mean
示例8: get_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def get_path( img, verts ):
#verts=array( verts, int)
path1 = Path(verts)
print path1
dx,dy=img.shape
data = zeros( [dx,dy,2])
data[:,:,0]= range(dx)
for i in range(dy):
data[i,:,1] = i
#print data
data=data.reshape( [dx*dy,2])
#print data.shape
#print path1,data
index = path1.contains_points(data)
print index.shape, len(where(index)[0])
#print data[index, :2]
#plot(data[:,0],data[:,1], 'b.')
fig, ax = plt.subplots(nrows=1)
vmin=img.min();vmax=img.max()
ax.imshow( img,cmap=plt.get_cmap('winter'), vmin=vmin,vmax=vmax )
#ax.set_xlim(0,dx-1)
#ax.set_ylim(0,dy-1)
patch = patches.PathPatch(path1, facecolor='orange', lw=2)
gca().add_patch(patch)
plot(data[index,0], data[index,1], 'r.')
show()
示例9: onselect
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def onselect(self, verts):
path = Path(verts)
self.ind = np.nonzero(path.contains_points(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()
示例10: get_mask_img
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def get_mask_img(transform, target_bin, camera_model):
"""
:param point: point that is going to be transformed
:type point: PointStamped
:param transform: camera_frame -> bbox_frame
:type transform: Transform
"""
# check frame_id of a point and transform just in case
assert camera_model.tf_frame == transform.header.frame_id
assert target_bin.bbox.header.frame_id == transform.child_frame_id
transformed_list = [
do_transform_point(corner, transform)
for corner in target_bin.corners]
projected_points = project_points(transformed_list, camera_model)
# generate an polygon that covers the region
path = Path(projected_points)
x, y = np.meshgrid(
np.arange(camera_model.width),
np.arange(camera_model.height))
x, y = x.flatten(), y.flatten()
points = np.vstack((x, y)).T
mask_img = path.contains_points(
points).reshape(
camera_model.height, camera_model.width
).astype('bool')
return mask_img
示例11: test_point_in_path_nan
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def test_point_in_path_nan():
box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
p = Path(box)
test = np.array([[np.nan, 0.5]])
contains = p.contains_points(test)
assert len(contains) == 1
assert not contains[0]
示例12: paths_in_shape
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def paths_in_shape(paths):
shape = shape_(shape_path)
minx, miny, maxx, maxy = shape.bounds
#print minx; print miny; print maxx; print maxy
#bounding_box = geometry.box(minx, miny, maxx, maxy)
#generate random points within bounding box!
sf = shapefile.Reader(shape_path)
shape = sf.shapes()[0]
#find polygon nodes lat lons
verticies = shape.points
#convert to a matplotlib path class!
polygon = Path(verticies)
points_in_shape = polygon.contains_points(paths)
points_in_shape = paths[points_in_shape == True]
return points_in_shape
示例13: subsample
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def subsample(self, vertices):
xiyi = np.vstack((self.traj_lon[0,:], self.traj_lat[0,:])).T
mpath = MplPath( vertices )
outside_area = ~mpath.contains_points(xiyi)
self.init_x, self.init_y, self.init_z, self.init_s, \
self.traj_lon, self.traj_lat, self.traj_depth, self.traj_time, self.final_z = \
[x.compress(outside_area,axis=-1) for x in (self.init_x, self.init_y, self.init_z, self.init_s,
self.traj_lon, self.traj_lat, self.traj_depth, self.traj_time, self.final_z)]
示例14: test_point_in_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def test_point_in_path():
# Test #1787
verts2 = [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]
path = Path(verts2, closed=True)
points = [(0.5, 0.5), (1.5, 0.5)]
assert np.all(path.contains_points(points) == [True, False])
示例15: _in_polygon
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import contains_points [as 别名]
def _in_polygon(points, polygon):
"""Return the points that are inside a polygon."""
from matplotlib.path import Path
points = _as_array(points)
polygon = _as_array(polygon)
assert points.ndim == 2
assert polygon.ndim == 2
path = Path(polygon, closed=True)
return path.contains_points(points)