本文整理汇总了Python中matplotlib.path.Path.CLOSEPOLY属性的典型用法代码示例。如果您正苦于以下问题:Python Path.CLOSEPOLY属性的具体用法?Python Path.CLOSEPOLY怎么用?Python Path.CLOSEPOLY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类matplotlib.path.Path
的用法示例。
在下文中一共展示了Path.CLOSEPOLY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: poly2patch
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def poly2patch(self, poly2d, closed=False, alpha=1., color=None):
moves = {'L': Path.LINETO,
'C': Path.CURVE4}
points = [p[:2] for p in poly2d]
codes = [moves[p[2]] for p in poly2d]
codes[0] = Path.MOVETO
if closed:
points.append(points[0])
if codes[-1] == 4:
codes.append(Path.LINETO)
else:
codes.append(Path.CLOSEPOLY)
if color is None:
color = random_color()
# print(codes, points)
return mpatches.PathPatch(
Path(points, codes),
facecolor=color if closed else 'none',
edgecolor=color, # if not closed else 'none',
lw=1 if closed else 2 * self.scale, alpha=alpha,
antialiased=False, snap=True)
示例2: poly2patch
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def poly2patch(self, poly2d, closed=False, alpha=1., color=None):
moves = {'L': Path.LINETO,
'C': Path.CURVE4}
points = [p[:2] for p in poly2d]
codes = [moves[p[2]] for p in poly2d]
codes[0] = Path.MOVETO
if closed:
points.append(points[0])
codes.append(Path.CLOSEPOLY)
if color is None:
color = random_color()
# print(codes, points)
return mpatches.PathPatch(
Path(points, codes),
facecolor=color if closed else 'none',
edgecolor=color, # if not closed else 'none',
lw=1 if closed else 2 * self.scale, alpha=alpha,
antialiased=False, snap=True)
示例3: get_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def get_path(self):
x0, y0, x1, y1 = self.bbox.extents
verts = [(x0, y0),
(x1, y0),
(x1, y1),
(x0, y1),
(x0, y0),
(0,0)]
codes = [Path.MOVETO,
Path.LINETO,
Path.LINETO,
Path.LINETO,
Path.LINETO,
Path.CLOSEPOLY]
return Path(verts, codes)
示例4: _append_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def _append_path(ctx, path, transform, clip=None):
for points, code in path.iter_segments(
transform, remove_nans=True, clip=clip):
if code == Path.MOVETO:
ctx.move_to(*points)
elif code == Path.CLOSEPOLY:
ctx.close_path()
elif code == Path.LINETO:
ctx.line_to(*points)
elif code == Path.CURVE3:
cur = np.asarray(ctx.get_current_point())
a = points[:2]
b = points[-2:]
ctx.curve_to(*(cur / 3 + a * 2 / 3), *(a * 2 / 3 + b / 3), *b)
elif code == Path.CURVE4:
ctx.curve_to(*points)
示例5: transmute
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def transmute(self, path, mutation_size, linewidth):
x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
b_plus, b_minus = make_wedged_bezier2(
arrow_path,
self.tail_width * mutation_size / 2.,
wm=self.shrink_factor)
patch_path = [(Path.MOVETO, b_plus[0]),
(Path.CURVE3, b_plus[1]),
(Path.CURVE3, b_plus[2]),
(Path.LINETO, b_minus[2]),
(Path.CURVE3, b_minus[1]),
(Path.CURVE3, b_minus[0]),
(Path.CLOSEPOLY, b_minus[0]),
]
path = Path([p for c, p in patch_path], [c for c, p in patch_path])
return path, True
示例6: test_clipping_of_log
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def test_clipping_of_log():
# issue 804
M,L,C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY
points = [ (0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99) ]
codes = [ M, L, L, L, C ]
path = Path(points, codes)
# something like this happens in plotting logarithmic histograms
trans = BlendedGenericTransform(Affine2D(),
LogScale.Log10Transform('clip'))
tpath = trans.transform_path_non_affine(path)
result = tpath.iter_segments(trans.get_affine(),
clip=(0, 0, 100, 100),
simplify=False)
tpoints, tcodes = list(zip(*result))
# Because y coordinate -99 is outside the clip zone, the first
# line segment is effectively removed. That means that the closepoly
# operation must be replaced by a move to the first point.
assert np.allclose(tcodes, [ M, M, L, L, L ])
示例7: _append_paths_slow
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def _append_paths_slow(ctx, paths, transforms, clip=None):
for path, transform in zip(paths, transforms):
for points, code in path.iter_segments(transform, clip=clip):
if code == Path.MOVETO:
ctx.move_to(*points)
elif code == Path.CLOSEPOLY:
ctx.close_path()
elif code == Path.LINETO:
ctx.line_to(*points)
elif code == Path.CURVE3:
cur = ctx.get_current_point()
ctx.curve_to(
*np.concatenate([cur / 3 + points[:2] * 2 / 3,
points[:2] * 2 / 3 + points[-2:] / 3]))
elif code == Path.CURVE4:
ctx.curve_to(*points)
示例8: polygon
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def polygon(pts, img_shape):
# codes = [Path.MOVETO,
# Path.LINETO,
# Path.LINETO,
# Path.LINETO,
# Path.CLOSEPOLY,
# ]
x, y = np.meshgrid(np.arange(img_shape[0]), np.arange(img_shape[1]))
x, y = x.flatten(), y.flatten()
points = np.vstack((x, y)).T
path = Path(pts)
grid = path.contains_points(points)
mask = grid.reshape((img_shape[0], img_shape[1]))
# y, x = np.where(grid)
return mask
示例9: svg_parse
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def svg_parse(path):
commands = {'M': (Path.MOVETO,),
'L': (Path.LINETO,),
'Q': (Path.CURVE3,)*2,
'C': (Path.CURVE4,)*3,
'Z': (Path.CLOSEPOLY,)}
path_re = re.compile(r'([MLHVCSQTAZ])([^MLHVCSQTAZ]+)', re.IGNORECASE)
float_re = re.compile(r'(?:[\s,]*)([+-]?\d+(?:\.\d+)?)')
vertices = []
codes = []
last = (0, 0)
for cmd, values in path_re.findall(path):
points = [float(v) for v in float_re.findall(values)]
points = np.array(points).reshape((len(points)//2, 2))
if cmd.islower():
points += last
cmd = cmd.capitalize()
last = points[-1]
codes.extend(commands[cmd])
vertices.extend(points.tolist())
return codes, vertices
# SVG to matplotlib
示例10: _append_paths_slow
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def _append_paths_slow(ctx, paths, transforms, clip=None):
for path, transform in zip(paths, transforms):
for points, code in path.iter_segments(
transform, remove_nans=True, clip=clip):
if code == Path.MOVETO:
ctx.move_to(*points)
elif code == Path.CLOSEPOLY:
ctx.close_path()
elif code == Path.LINETO:
ctx.line_to(*points)
elif code == Path.CURVE3:
cur = np.asarray(ctx.get_current_point())
a = points[:2]
b = points[-2:]
ctx.curve_to(*(cur / 3 + a * 2 / 3), *(a * 2 / 3 + b / 3), *b)
elif code == Path.CURVE4:
ctx.curve_to(*points)
示例11: test_clipping_of_log
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def test_clipping_of_log():
# issue 804
M, L, C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY
points = [(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)]
codes = [M, L, L, L, C]
path = Path(points, codes)
# something like this happens in plotting logarithmic histograms
trans = mtransforms.BlendedGenericTransform(mtransforms.Affine2D(),
LogScale.Log10Transform('clip'))
tpath = trans.transform_path_non_affine(path)
result = tpath.iter_segments(trans.get_affine(),
clip=(0, 0, 100, 100),
simplify=False)
tpoints, tcodes = zip(*result)
assert_allclose(tcodes, [M, L, L, L, C])
示例12: test_transformed_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def test_transformed_path():
points = [(0, 0), (1, 0), (1, 1), (0, 1)]
codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
path = Path(points, codes)
trans = mtransforms.Affine2D()
trans_path = mtransforms.TransformedPath(path, trans)
assert_allclose(trans_path.get_fully_transformed_path().vertices, points)
# Changing the transform should change the result.
r2 = 1 / np.sqrt(2)
trans.rotate(np.pi / 4)
assert_allclose(trans_path.get_fully_transformed_path().vertices,
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)],
atol=1e-15)
# Changing the path does not change the result (it's cached).
path.points = [(0, 0)] * 4
assert_allclose(trans_path.get_fully_transformed_path().vertices,
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)],
atol=1e-15)
示例13: test_customcell
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def test_customcell():
types = ('horizontal', 'vertical', 'open', 'closed', 'T', 'R', 'B', 'L')
codes = (
(Path.MOVETO, Path.LINETO, Path.MOVETO, Path.LINETO, Path.MOVETO),
(Path.MOVETO, Path.MOVETO, Path.LINETO, Path.MOVETO, Path.LINETO),
(Path.MOVETO, Path.MOVETO, Path.MOVETO, Path.MOVETO, Path.MOVETO),
(Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY),
(Path.MOVETO, Path.MOVETO, Path.MOVETO, Path.LINETO, Path.MOVETO),
(Path.MOVETO, Path.MOVETO, Path.LINETO, Path.MOVETO, Path.MOVETO),
(Path.MOVETO, Path.LINETO, Path.MOVETO, Path.MOVETO, Path.MOVETO),
(Path.MOVETO, Path.MOVETO, Path.MOVETO, Path.MOVETO, Path.LINETO),
)
for t, c in zip(types, codes):
cell = CustomCell((0, 0), visible_edges=t, width=1, height=1)
code = tuple(s for _, s in cell.get_path().iter_segments())
assert c == code
示例14: DrawShapeFile
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def DrawShapeFile(area):
"""
在画布上绘制shp文件
:param area: 包含shp文件名及线宽和线颜色的一个字典
:return:
"""
try:
shpfile = area.file
border_shape = shapefile.Reader(shpfile)
border = border_shape.shapes()
for b in border:
border_points = b.points
path_data = []
count = 0
for cell in border_points:
if count == 0:
trans = (Path.MOVETO, (cell[0], cell[1]))
path_data += [trans]
cell_end = cell
else:
trans = (Path.CURVE4, (cell[0], cell[1]))
path_data += [trans]
trans = (Path.CLOSEPOLY, (cell_end[0], cell_end[1]))
path_data += [trans]
codes, verts = list(zip(*path_data))
path = Path(verts, codes)
x, y = list(zip(*path.vertices))
plt.plot(x, y, 'k-', linewidth=area.linewidth, color=area.linecolor)
except Exception as err:
print(u'【{0}】{1}-{2}'.format(area['file'], err, datetime.now()))
示例15: getPathFromShp
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import CLOSEPOLY [as 别名]
def getPathFromShp(shpfile, region):
try:
sf = shapefile.Reader(shpfile)
vertices = [] # 这块是已经修改的地方
codes = [] # 这块是已经修改的地方
paths = []
for shape_rec in sf.shapeRecords():
# if shape_rec.record[3] == region: # 这里需要找到和region匹配的唯一标识符,record[]中必有一项是对应的。
if region == [100000] or shape_rec.record[4] in region: # 这块是已经修改的地方
pts = shape_rec.shape.points
prt = list(shape_rec.shape.parts) + [len(pts)]
for i in range(len(prt) - 1):
for j in range(prt[i], prt[i + 1]):
vertices.append((pts[j][0], pts[j][1]))
codes += [Path.MOVETO]
codes += [Path.LINETO] * (prt[i + 1] - prt[i] - 2)
codes += [Path.CLOSEPOLY]
path = Path(vertices, codes)
paths.append(path)
if paths:
path = Path.make_compound_path(*paths)
else:
path = None
return path
except Exception as err:
print(err)
return None