本文整理汇总了Python中matplotlib.path.Path方法的典型用法代码示例。如果您正苦于以下问题:Python path.Path方法的具体用法?Python path.Path怎么用?Python path.Path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.path
的用法示例。
在下文中一共展示了path.Path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readPolygon
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def readPolygon(filename):
"""
从特定格式的文件中获取path
:param filename: 特定的数据文件全名
:return: path对象的一个实例
"""
try:
file_object = open(filename)
all_the_text = file_object.read().strip()
file_object.close()
poses = re.split(r'[,]+|[\s]+', all_the_text)
lon = [float(p) for p in poses[0::2]]
lat = [float(p) for p in poses[1::2]]
path = Path(zip(lon, lat))
return path
except Exception as err:
print(u'【{0}】{1}-{2}'.format(filename, err, datetime.now()))
return None
示例2: readPath
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def readPath(filename, start_pos=13):
"""
从类似第9类micaps数据中获取path
:param start_pos:
:param filename: 数据文件全名
:return: path对象的一个实例
"""
try:
file_object = open(filename)
all_the_text = file_object.read()
file_object.close()
poses = all_the_text.strip().split()
lon = [float(p) for p in poses[start_pos::2]]
lat = [float(p) for p in poses[start_pos+1::2]]
path = Path(zip(lon, lat))
return path
except Exception as err:
print(u'【{0}】{1}-{2}'.format(filename, err, datetime.now()))
return None
示例3: ConvertPacth
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def ConvertPacth(self, ax, patch):
path = patch.get_path()
lon = []
lat = []
for points in path.vertices:
x, y = points[0], points[1]
xy_pixels = ax.transData.transform(np.vstack([x, y]).T)
xpix, ypix = xy_pixels.T
lon.append(xpix[0])
lat.append(ypix[0])
from matplotlib.path import Path
apath = Path(list(zip(lon, lat)))
from matplotlib import patches
apatch = patches.PathPatch(apath, linewidth=1, facecolor='none', edgecolor='k')
plt.gca().add_patch(apatch)
return apatch
示例4: set_verts
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def set_verts(self, verts, closed=True):
'''This allows one to delay initialization of the vertices.'''
if np.ma.isMaskedArray(verts):
verts = verts.astype(np.float_).filled(np.nan)
# This is much faster than having Path do it one at a time.
if closed:
self._paths = []
for xy in verts:
if len(xy):
if np.ma.isMaskedArray(xy):
xy = np.ma.concatenate([xy, np.zeros((1, 2))])
else:
xy = np.asarray(xy)
xy = np.concatenate([xy, np.zeros((1, 2))])
codes = np.empty(xy.shape[0], dtype=mpath.Path.code_type)
codes[:] = mpath.Path.LINETO
codes[0] = mpath.Path.MOVETO
codes[-1] = mpath.Path.CLOSEPOLY
self._paths.append(mpath.Path(xy, codes))
else:
self._paths.append(mpath.Path(xy))
else:
self._paths = [mpath.Path(xy) for xy in verts]
示例5: convert_mesh_to_paths
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
"""
Converts a given mesh into a sequence of
:class:`matplotlib.path.Path` objects for easier rendering by
backends that do not directly support quadmeshes.
This function is primarily of use to backend implementers.
"""
Path = mpath.Path
if ma.isMaskedArray(coordinates):
c = coordinates.data
else:
c = coordinates
points = np.concatenate((
c[0:-1, 0:-1],
c[0:-1, 1:],
c[1:, 1:],
c[1:, 0:-1],
c[0:-1, 0:-1]
), axis=2)
points = points.reshape((meshWidth * meshHeight, 5, 2))
return [Path(x) for x in points]
示例6: draw
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def draw(self, renderer):
"""
Draw the children
"""
dpi_cor = renderer.points_to_pixels(1.)
self.dpi_transform.clear()
self.dpi_transform.scale(dpi_cor, dpi_cor)
# At this point the DrawingArea has a transform
# to the display space so the path created is
# good for clipping children
tpath = mtransforms.TransformedPath(
mpath.Path([[0, 0], [0, self.height],
[self.width, self.height],
[self.width, 0]]),
self.get_transform())
for c in self._children:
if self._clip_children and not (c.clipbox or c._clippath):
c.set_clip_path(tpath)
c.draw(renderer)
bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
self.stale = False
示例7: linear_spine
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def linear_spine(cls, axes, spine_type, **kwargs):
"""
(staticmethod) Returns a linear :class:`Spine`.
"""
# all values of 0.999 get replaced upon call to set_bounds()
if spine_type == 'left':
path = mpath.Path([(0.0, 0.999), (0.0, 0.999)])
elif spine_type == 'right':
path = mpath.Path([(1.0, 0.999), (1.0, 0.999)])
elif spine_type == 'bottom':
path = mpath.Path([(0.999, 0.0), (0.999, 0.0)])
elif spine_type == 'top':
path = mpath.Path([(0.999, 1.0), (0.999, 1.0)])
else:
raise ValueError('unable to make path for spine "%s"' % spine_type)
result = cls(axes, spine_type, path, **kwargs)
result.set_visible(rcParams['axes.spines.{0}'.format(spine_type)])
return result
示例8: inside_polygon
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def inside_polygon(polygon, point):
""" check if a point is strictly inside the polygon
:param ndarray|list polygon: polygon contour
:param tuple|list point: sample point
:return bool: inside
>>> poly = [[1, 1], [1, 3], [3, 3], [3, 1]]
>>> inside_polygon(poly, [0, 0])
False
>>> inside_polygon(poly, [1, 1])
False
>>> inside_polygon(poly, [2, 2])
True
"""
path = Path(polygon)
return path.contains_points([point])[0]
示例9: make_mask
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def make_mask(mask_size, box, polygons_list):
"""
Mask size: int about how big mask will be
box: [x1, y1, x2, y2, conf.]
polygons_list: List of polygons that go inside the box
"""
mask = np.zeros((mask_size, mask_size), dtype=np.bool)
xy = np.meshgrid(_spaced_points(box[0], box[2], n=mask_size),
_spaced_points(box[1], box[3], n=mask_size))
xy_flat = np.stack(xy, 2).reshape((-1, 2))
for polygon in polygons_list:
polygon_path = path.Path(polygon)
mask |= polygon_path.contains_points(xy_flat).reshape((mask_size, mask_size))
return mask.astype(np.float32)
#
#from matplotlib import pyplot as plt
#
#
#with open('XdtbL0dP0X0@44.json', 'r') as f:
# metadata = json.load(f)
#from time import time
#s = time()
#for i in range(100):
# mask = make_mask(14, metadata['boxes'][3], metadata['segms'][3])
#print("Elapsed {:3f}s".format(time()-s))
#plt.imshow(mask)
示例10: get_mask
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def get_mask(self, current_image):
ny, nx = np.shape(current_image)
poly_verts = ([(self.x[0], self.y[0])]
+ list(zip(reversed(self.x), reversed(self.y))))
# Create vertex coordinates for each grid cell...
# (<0,0> is at the top left of the grid in this system)
x, y = np.meshgrid(np.arange(nx), np.arange(ny))
x, y = x.flatten(), y.flatten()
points = np.vstack((x, y)).T
roi_path = MplPath(poly_verts)
grid = roi_path.contains_points(points).reshape((ny, nx))
return grid
示例11: draw_ordered_polys
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def draw_ordered_polys(o_polys):
for poly in o_polys:
ax = plt.gca()
path = mpp.Path(poly[:, 0:2])
patch = patches.PathPatch(path, facecolor='orange', lw=1)
ax.add_patch(patch)
示例12: point_in_geometry
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def point_in_geometry(o_polys, point):
for poly in o_polys:
path = mpp.Path(poly[:, 0:2])
inside = path.contains_points([point])
if inside:
return True
return False
示例13: inside_poly
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def inside_poly(points, verts):
"""
*points* is a sequence of *x*, *y* points.
*verts* is a sequence of *x*, *y* vertices of a polygon.
Return value is a sequence of indices into points for the points
that are inside the polygon.
"""
# Make a closed polygon path
poly = Path( verts )
# Check to see which points are contained withing the Path
return [ idx for idx, p in enumerate(points) if poly.contains_point(p) ]
示例14: transform_path_non_affine
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def transform_path_non_affine(self, path):
vertices = path.vertices
ipath = path.interpolated(self._resolution)
return Path(self.transform(ipath.vertices), ipath.codes)
示例15: transform_path_non_affine
# 需要导入模块: from matplotlib import path [as 别名]
# 或者: from matplotlib.path import Path [as 别名]
def transform_path_non_affine(self, path):
vertices = path.vertices
if len(vertices) == 2 and vertices[0, 0] == vertices[1, 0]:
return Path(self.transform(vertices), path.codes)
ipath = path.interpolated(path._interpolation_steps)
return Path(self.transform(ipath.vertices), ipath.codes)