本文整理汇总了Python中matplotlib.path.Path.make_compound_path方法的典型用法代码示例。如果您正苦于以下问题:Python Path.make_compound_path方法的具体用法?Python Path.make_compound_path怎么用?Python Path.make_compound_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.path.Path
的用法示例。
在下文中一共展示了Path.make_compound_path方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import make_compound_path [as 别名]
def main():
imagery = OSM()
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=imagery.crs)
ax.set_extent([-0.14, -0.1, 51.495, 51.515], ccrs.PlateCarree())
# Construct concentric circles and a rectangle,
# suitable for a London Underground logo.
theta = np.linspace(0, 2 * np.pi, 100)
circle_verts = np.vstack([np.sin(theta), np.cos(theta)]).T
concentric_circle = Path.make_compound_path(Path(circle_verts[::-1]),
Path(circle_verts * 0.6))
rectangle = Path([[-1.1, -0.2], [1, -0.2], [1, 0.3], [-1.1, 0.3]])
# Add the imagery to the map.
ax.add_image(imagery, 14)
# Plot the locations twice, first with the red concentric circles,
# then with the blue rectangle.
xs, ys = tube_locations().T
ax.plot(xs, ys, transform=ccrs.OSGB(),
marker=concentric_circle, color='red', markersize=9, linestyle='')
ax.plot(xs, ys, transform=ccrs.OSGB(),
marker=rectangle, color='blue', markersize=11, linestyle='')
ax.set_title('London underground locations')
plt.show()
示例2: transform_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import make_compound_path [as 别名]
def transform_path(self, path):
vertices = path.vertices
# Intelligent interpolation needed
# ipath = path.interpolated(self._resolution)
ipath = path
ipath = path.interpolated(10)
# ipath = path.interpolated(3050)
verts = self.transform_no_mod(ipath.vertices)
codes = ipath.codes
# print verts.shape
# print 'transforming lon range:', np.min(verts[:, 0]), np.max(verts[:, 0])
# if np.isnan(np.max(verts[:, 0])):
# print 'Got nan: ', path, verts
paths = []
paths.append(Path(verts, codes))
# # Have any of the points wrapped? If so, pick up the pen, and start from -360
# if any(ipath.vertices[:, 0] > np.pi):
# v = ipath.vertices.copy()
# print 'splitting -:'
# v[:, 0] -= 2 * np.pi
# print v
# v = self.transform_no_mod(v)
# paths.append(Path(v))
#
# # Have any of the points wrapped? If so, pick up the pen, and start from +360
# if any(ipath.vertices[:, 0] < -np.pi):
# v = ipath.vertices.copy()
# v[:, 0] += 2 * np.pi
# print 'splitting +:'
# v = self.transform_no_mod(v)
# paths.append(Path(v))
s_pole = np.deg2rad(np.array([0, -89.9999]))
if path.contains_point(s_pole):
print 'POLE ALERT!!!', path
path = Path(verts[:-31])
paths = [path]
if len(paths) == 1:
path = paths[0]
else:
for path in paths:
if path.codes is not None:
if path.codes[0] == Path.MOVETO and all(path.codes[1:] == Path.LINETO):
path.codes = None
else:
# This is a bit strict... but a condition of make_compound_path
raise ValueError('Cannot draw discontiguous polygons.')
# print path.codes
path = Path.make_compound_path(*paths)
return path
示例3: _plot
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import make_compound_path [as 别名]
def _plot(self, ax, legend, alpha, ec='#222222'):
groups = self.groups('shape')
for key in self.classes.index:
group = groups.get_group(key)
paths = []
for g in group['shape']:
paths.append(PolygonPath(g))
patch = PathPatch(Path.make_compound_path(*paths), fc=legend[key], ec=ec, alpha=alpha, zorder=2, label='{} ({})'.format(key, len(group)))
ax.add_patch(patch)
ax.margins(0.025, 0.025)
ax.get_yaxis().set_tick_params(which='both', direction='out')
ax.get_xaxis().set_tick_params(which='both', direction='out')
return ax
示例4: test_make_compound_path_empty
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import make_compound_path [as 别名]
def test_make_compound_path_empty():
# We should be able to make a compound path with no arguments.
# This makes it easier to write generic path based code.
r = Path.make_compound_path()
assert r.vertices.shape == (0, 2)
示例5: compress_points
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import make_compound_path [as 别名]
def compress_points(points):
bi, bj, bx, by = get_boundary_intersections(points)
f = bi == bj
alone_points = points[bi[f]]
alone_paths = [Path.circle(xy, 0.5) for xy in alone_points]
edge_lists = [[] for i in range(len(points))]
n = 0
for i, j, x, y in zip(bi, bj, bx, by):
if i != j:
edge_lists[j].append((i, x, y))
n += 1
print("%s points in total: %s edges, %s alone points" %
(len(points), n, len(alone_points)))
def patan2(dy, dx):
"""
Return pseudo-arctangent of dy/dx such that
patan2(y1, x1) < patan2(y2, x2)
if and only if
atan2(y1, x1) < atan2(y2, x2)
"""
if dy > 0 and dx > 0:
return (0, dy - dx)
elif dy > 0 and dx <= 0:
return (1, -dy - dx)
elif dy <= 0 and dx > 0:
return (2, dx - dy)
else:
return (3, dx + dy)
def shift(u, v):
if v < u:
return (v[0] + 4, v[1])
else:
return v
def pop_next(i, ox, oy):
def local_patan2(y, x):
return patan2(y - points[i, 1], x - points[i, 0])
u = local_patan2(oy, ox)
j = min(range(len(edge_lists[i])),
key=lambda j: shift(u, local_patan2(edge_lists[i][j][2],
edge_lists[i][j][1])))
return edge_lists[i].pop(j)
paths = []
# print("<path fill=\"black\" fillrule=\"wind\">")
while n > 0:
assert sum(len(e) for e in edge_lists) == n
i = 0
while not edge_lists[i]:
i += 1
start = i
j, ox, oy = edge_lists[i].pop(0)
startx, starty = ox, oy
ux, uy = ox, oy
# path = ['%s %s m' % (startx, starty)]
path_vert_lists = [[[startx, starty]]]
path_code_lists = [[Path.MOVETO]]
n -= 1
while j != start:
i = j
j, vx, vy = pop_next(i, ux, uy)
n -= 1
# path.append(
# '%s 0 0 %s %s %s %s %s a' %
# (R, R, points[i, 0], points[i, 1], ox, oy))
ox, oy = points[i]
theta1 = np.arctan2(uy - oy, ux - ox)
theta2 = np.arctan2(vy - oy, vx - ox)
a = Path.arc(theta1 * 180 / np.pi, theta2 * 180 / np.pi)
a = a.transformed(Affine2D().scale(0.5).translate(ox, oy))
path_vert_lists.append(a._vertices[1:])
path_code_lists.append(a._codes[1:])
ux, uy = vx, vy
# path.append(
# '%s 0 0 %s %s %s %s %s a' %
# (R, R, points[j, 0], points[j, 1], startx, starty))
ox, oy = points[j]
theta1 = np.arctan2(uy - oy, ux - ox)
theta2 = np.arctan2(starty - oy, startx - ox)
a = Path.arc(theta1 * 180 / np.pi, theta2 * 180 / np.pi)
a = a.transformed(Affine2D().scale(0.5).translate(ox, oy))
path_vert_lists.append(a._vertices[1:])
path_code_lists.append(a._codes[1:])
# print('\n'.join(path))
paths.append(
Path(np.concatenate(path_vert_lists),
np.concatenate(path_code_lists).astype(Path.code_type)))
# print("</path>")
return Path.make_compound_path(*(alone_paths + paths))