本文整理汇总了Python中matplotlib.path.Path.MOVETO属性的典型用法代码示例。如果您正苦于以下问题:Python Path.MOVETO属性的具体用法?Python Path.MOVETO怎么用?Python Path.MOVETO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类matplotlib.path.Path
的用法示例。
在下文中一共展示了Path.MOVETO属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transmute
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [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
示例2: get_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [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)
示例3: poly2patch
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [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)
示例4: draw_wire
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def draw_wire(axis, source, target,
bend_out=False, bend_in=False, to_tikz=False):
"""
Draws a wire from source to target using a Bezier curve.
"""
mid = (target[0], source[1]) if bend_out else (source[0], target[1])
if to_tikz == "controls":
cmd = "\\draw {} .. controls {} .. {};\n"
axis.append(cmd.format(*("({}, {})".format(*point)
for point in [source, mid, target])))
elif to_tikz:
out = -90 if not bend_out or source[0] == target[0]\
else (180 if source[0] > target[0] else 0)
inp = 90 if not bend_in or source[0] == target[0]\
else (180 if source[0] < target[0] else 0)
cmd = "\\draw [out={}, in={}] {{}} to {{}};\n".format(out, inp)
axis.append(cmd.format(*("({}, {})".format(*point)
for point in [source, target])))
else:
path = Path([source, mid, target],
[Path.MOVETO, Path.CURVE3, Path.CURVE3])
axis.add_patch(PathPatch(path, facecolor='none'))
示例5: poly2patch
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [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)
示例6: connect
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def connect(self, posA, posB):
x1, y1 = posA
x2, y2 = posB
x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
dx, dy = x2 - x1, y2 - y1
f = self.rad
cx, cy = x12 + f * dy, y12 - f * dx
vertices = [(x1, y1),
(cx, cy),
(x2, y2)]
codes = [Path.MOVETO,
Path.CURVE3,
Path.CURVE3]
return Path(vertices, codes)
示例7: _get_bracket
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def _get_bracket(self, x0, y0,
cos_t, sin_t, width, length,
):
# arrow from x0, y0 to x1, y1
from matplotlib.bezier import get_normal_points
x1, y1, x2, y2 = get_normal_points(x0, y0, cos_t, sin_t, width)
dx, dy = length * cos_t, length * sin_t
vertices_arrow = [(x1 + dx, y1 + dy),
(x1, y1),
(x2, y2),
(x2 + dx, y2 + dy)]
codes_arrow = [Path.MOVETO,
Path.LINETO,
Path.LINETO,
Path.LINETO]
return vertices_arrow, codes_arrow
示例8: rounded_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def rounded_path(vertices, roundness, close=False):
'''make rounded path from vertices.'''
vertices = np.asarray(vertices)
if roundness == 0:
vertices = vertices if not close else np.concatenate([vertices, vertices[:1]],axis=0)
return Path(vertices, codes=[Path.MOVETO]+[Path.LINETO]*(len(vertices)-1))
if close:
vertices = np.concatenate([vertices, vertices[:2]], axis=0)
codes = [Path.MOVETO]
vertices_new = [vertices[0]]
if close:
cur, nex = vertices[:2]
vertices_new[0] = cur + (nex - cur)/norm(cur-nex)*roundness
for pre, cur, nex in zip(vertices[:-2], vertices[1:-1], vertices[2:]):
codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
dv_pre = (pre - cur)/norm(cur-pre)*roundness
dv_nex = (nex - cur)/norm(cur-nex)*roundness
vertices_new.extend([cur+dv_pre,cur,cur+dv_nex])
if not close:
codes.append(Path.LINETO)
vertices_new.append(vertices[-1])
return Path(vertices_new, codes)
示例9: rounded_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def rounded_path(vertices, roundness):
'''make rounded path from vertices.'''
vertices = np.asarray(vertices)
if roundness == 0:
return Path(vertices)
codes = [Path.MOVETO]
vertices_new = [vertices[0]]
for pre, cur, nex in zip(vertices[:-2], vertices[1:-1], vertices[2:]):
codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
dv_pre = (pre - cur)/norm(cur-pre)*roundness
dv_nex = (nex - cur)/norm(cur-nex)*roundness
vertices_new.extend([cur+dv_pre,cur,cur+dv_nex])
codes.append(Path.LINETO)
vertices_new.append(vertices[-1])
return Path(vertices_new, codes)
示例10: _draw_powerline_line
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def _draw_powerline_line(self,
pos_or_x, pos_or_y,
pos_ex_x, pos_ex_y,
color, line_style):
codes = [
Path.MOVETO,
Path.LINETO
]
verts = [
(pos_or_x, pos_or_y),
(pos_ex_x, pos_ex_y)
]
path = Path(verts, codes)
patch = patches.PathPatch(path,
color=color,
lw=self._line_color_width,
ls=line_style)
self.ax.add_patch(patch)
示例11: DrawShapeFile
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [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()))
示例12: getPathFromShp
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [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
示例13: setPlot
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def setPlot(self):
#绘制跑道
verts = [
(self.rX[0] - self.xOffset, self.rY[0] + self.yOffset),
(self.rX[1] - self.xOffset, self.rY[1] + self.yOffset),
(self.rX[1] + self.xOffset, self.rY[1] - self.yOffset),
(self.rX[0] + self.xOffset, self.rY[0] - self.yOffset),
(self.rX[0] - self.xOffset, self.rY[0] + self.yOffset)
]
codes = [
Path.MOVETO,
Path.LINETO,
Path.LINETO,
Path.LINETO,
Path.CLOSEPOLY,
]
path = Path(verts, codes)
patch = patches.PathPatch(path, facecolor='white', alpha = 0.3)
self.plotLayer.add_patch(patch)
#绘制边界
self.plotLayer.plot([self.rX[0] - self.xOffset, self.rX[1] - self.xOffset], [self.rY[0] + self.yOffset, self.rY[1] + self.yOffset], 'w')
self.plotLayer.plot([self.rX[0] + self.xOffset, self.rX[1] + self.xOffset], [self.rY[0] - self.yOffset, self.rY[1] - self.yOffset], 'w')
#绘制车道
for i in xrange(1,self.lanes+1):
self.plotLayer.plot()
示例14: plot_2d_mixing_space
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def plot_2d_mixing_space(self, features, hold=False):
'''
Draws a 2D (triangular) mixing space.
'''
codes = [VectorPath.MOVETO, VectorPath.LINETO, VectorPath.LINETO, VectorPath.CLOSEPOLY]
verts = features[...,0:2].tolist()
verts.append((0, 0)) # Dummy vertex
path = VectorPath(verts, codes)
patch = patches.PathPatch(path, facecolor='black', alpha=0.3, lw=0)
plt.gca().add_patch(patch)
if not hold:
plt.show()
示例15: draw_polygon
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import MOVETO [as 别名]
def draw_polygon(axis, *points, to_tikz=False, color='#ffffff'):
"""
Draws a polygon from a list of points.
"""
if to_tikz:
axis.append("\\draw {};\n".format(" -- ".join(
"({}, {})".format(*x) for x in points + points[:1])))
else:
codes = [Path.MOVETO]
codes += len(points[1:]) * [Path.LINETO] + [Path.CLOSEPOLY]
path = Path(points + points[:1], codes)
axis.add_patch(PathPatch(path, facecolor=color))