本文整理汇总了Python中matplotlib.path.Path.unit_rectangle方法的典型用法代码示例。如果您正苦于以下问题:Python Path.unit_rectangle方法的具体用法?Python Path.unit_rectangle怎么用?Python Path.unit_rectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.path.Path
的用法示例。
在下文中一共展示了Path.unit_rectangle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import unit_rectangle [as 别名]
#.........这里部分代码省略.........
self._recompute_transform()
# Get the width and height in pixels
width = self.convert_xunits(self.width)
height = self.convert_yunits(self.height)
width, height = self.get_transform().transform_point(
(width, height))
inv_error = (1.0 / 1.89818e-6) * 0.5
if width < inv_error and height < inv_error:
self._path = Path.arc(self.theta1, self.theta2)
return Patch.draw(self, renderer)
def iter_circle_intersect_on_line(x0, y0, x1, y1):
dx = x1 - x0
dy = y1 - y0
dr2 = dx*dx + dy*dy
D = x0*y1 - x1*y0
D2 = D*D
discrim = dr2 - D2
# Single (tangential) intersection
if discrim == 0.0:
x = (D*dy) / dr2
y = (-D*dx) / dr2
yield x, y
elif discrim > 0.0:
# The definition of "sign" here is different from
# npy.sign: we never want to get 0.0
if dy < 0.0:
sign_dy = -1.0
else:
sign_dy = 1.0
sqrt_discrim = npy.sqrt(discrim)
for sign in (1., -1.):
x = (D*dy + sign * sign_dy * dx * sqrt_discrim) / dr2
y = (-D*dx + sign * npy.abs(dy) * sqrt_discrim) / dr2
yield x, y
def iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
epsilon = 1e-9
if x1 < x0:
x0e, x1e = x1, x0
else:
x0e, x1e = x0, x1
if y1 < y0:
y0e, y1e = y1, y0
else:
y0e, y1e = y0, y1
x0e -= epsilon
y0e -= epsilon
x1e += epsilon
y1e += epsilon
for x, y in iter_circle_intersect_on_line(x0, y0, x1, y1):
if x >= x0e and x <= x1e and y >= y0e and y <= y1e:
yield x, y
# Transforms the axes box_path so that it is relative to the unit
# circle in the same way that it is relative to the desired
# ellipse.
box_path = Path.unit_rectangle()
box_path_transform = transforms.BboxTransformTo(self.axes.bbox) + \
self.get_transform().inverted()
box_path = box_path.transformed(box_path_transform)
PI = npy.pi
TWOPI = PI * 2.0
RAD2DEG = 180.0 / PI
DEG2RAD = PI / 180.0
theta1 = self.theta1
theta2 = self.theta2
thetas = {}
# For each of the point pairs, there is a line segment
for p0, p1 in zip(box_path.vertices[:-1], box_path.vertices[1:]):
x0, y0 = p0
x1, y1 = p1
for x, y in iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
theta = npy.arccos(x)
if y < 0:
theta = TWOPI - theta
# Convert radians to angles
theta *= RAD2DEG
if theta > theta1 and theta < theta2:
thetas[theta] = None
thetas = thetas.keys()
thetas.sort()
thetas.append(theta2)
last_theta = theta1
theta1_rad = theta1 * DEG2RAD
inside = box_path.contains_point((npy.cos(theta1_rad), npy.sin(theta1_rad)))
for theta in thetas:
if inside:
self._path = Path.arc(last_theta, theta, 8)
Patch.draw(self, renderer)
inside = False
else:
inside = True
last_theta = theta
示例2: PathCollection
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import unit_rectangle [as 别名]
"Simple", "Wedge","BarAB"]
arrowstylelist = ["-","->","-[","-|>","<-","<->",
"<|-","<|-|>","]-","]-[", "fancy",
"simple", "wedge","|-|"]
colormaplist=sorted(m for m in matplotlib.cm.datad if not m.endswith('_r'))
#
# Artist may not reture the same value as given by setter...
# Also, matplotlib has a routine to get a list of valid property values.
# With get_valid_values, it may be possible to implement more automatic
# property list generation.
#
# The following is an initial attempt. Needs to check more how well
# matplotlib is organized in this aspect.
obj = PathCollection(Path.unit_rectangle())
plinestylelist, plinestyle_rlist = artist_property_checker(obj, 'linestyle')
pedgecolorlist, pedgecolor_rlist = artist_property_checker(obj, 'edgecolor', values =
"'"+"','".join(collist)+"'")
if isMPL2:
plinestylelist = plinestylelist[:4]
plinestyle_rlist = plinestyle_rlist[:4]
def colormap_list():
return colormaplist
def scratch_file():
return scratch
def color_list():
return collist
def color_list_face():
return collistf
示例3: get_path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import unit_rectangle [as 别名]
def get_path(self):
"""
Return the vertices of the rectangle
"""
return Path.unit_rectangle()
示例4: Path
# 需要导入模块: from matplotlib.path import Path [as 别名]
# 或者: from matplotlib.path.Path import unit_rectangle [as 别名]
Path.LINETO,
Path.LINETO,
Path.LINETO,
Path.LINETO,
Path.CLOSEPOLY,
]
path = Path(square_verts * scale, square_codes)
trans = matplotlib.transforms.Affine2D().translate(x, y)
t_path = path.transformed(trans)
patch = patches.PathPatch(t_path, facecolor=color.value, lw=line_weight, zorder=2)
a = ax.add_patch(patch)
ma = MonosaccharidePatch(saccharide_shape=(a,))
return ma
# return (a,)
draw_map[ResidueShape.square] = draw_square
unit_rectangle = Path.unit_rectangle()
def draw_triangle(ax, x, y, color, scale=0.1):
path = Path(unit_triangle.vertices * scale, unit_triangle.codes)
trans = matplotlib.transforms.Affine2D().translate(x, y).rotate_deg_around(x, y, -90)
t_path = path.transformed(trans)
patch = patches.PathPatch(t_path, facecolor=color.value, lw=line_weight, zorder=2)
a = ax.add_patch(patch)
ma = MonosaccharidePatch(saccharide_shape=(a,))
return ma
# return (a,)
draw_map[ResidueShape.triangle] = draw_triangle
unit_triangle = Path.unit_regular_polygon(3)