本文整理汇总了Python中matplotlib.patches.Wedge方法的典型用法代码示例。如果您正苦于以下问题:Python patches.Wedge方法的具体用法?Python patches.Wedge怎么用?Python patches.Wedge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches
的用法示例。
在下文中一共展示了patches.Wedge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_patch_str
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def test_patch_str():
"""
Check that patches have nice and working `str` representation.
Note that the logic is that `__str__` is defined such that:
str(eval(str(p))) == str(p)
"""
p = mpatches.Circle(xy=(1, 2), radius=3)
assert str(p) == 'Circle(xy=(1, 2), radius=3)'
p = mpatches.Ellipse(xy=(1, 2), width=3, height=4, angle=5)
assert str(p) == 'Ellipse(xy=(1, 2), width=3, height=4, angle=5)'
p = mpatches.Rectangle(xy=(1, 2), width=3, height=4, angle=5)
assert str(p) == 'Rectangle(xy=(1, 2), width=3, height=4, angle=5)'
p = mpatches.Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)
assert str(p) == 'Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)'
p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)
expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)'
assert str(p) == expected
示例2: _nucleotide_key_text_callback
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def _nucleotide_key_text_callback(patch: patches.Wedge,
nucleotide_body_patch: patches.Circle,
text_object, x_border=0.2, y_border=0.1):
# assumes that the coordinates are equal scaled in the view
radius = nucleotide_body_patch.radius
radius_with_width = radius + patch.width
radius_with_half_width = radius + patch.width / 2
initial_text_rotation = text_object.get_rotation()
text_object.set_rotation(0)
body_patch_window_extent = nucleotide_body_patch.get_window_extent()
scale_pixel_to_units = body_patch_window_extent.width / 2 / radius
wedge_height_pixel = scale_pixel_to_units * patch.width
wedge_width = (2 * np.pi * radius_with_half_width *
np.abs(patch.theta2 - patch.theta1) / 360)
text_width_max = min(
wedge_width,
2 * (radius_with_width ** 2 - radius_with_half_width ** 2) ** 0.5)
text_width_max_pixel = scale_pixel_to_units * text_width_max
_scale_font_size(text_object, text_width_max_pixel,
wedge_height_pixel, x_border, y_border)
text_object.set_rotation(initial_text_rotation)
示例3: draw_collision
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def draw_collision(self, ax, collision):
if collision == False:
if self.obj_collision == None:
return
else:
self.obj_collision.update({'visible':False})
else:
x = to_index(self.collision_pose.x, self.map_rows, self.xlim)
y = to_index(self.collision_pose.y, self.map_cols, self.ylim)
radius = self.cr_pixels #self.collision_radius / (self.xlim[1]-self.xlim[0]) * self.map_rows
if self.obj_collision == None:
self.obj_collision = Wedge((y,x), radius, 0, 360, color='y',alpha=0.5, visible=True)
ax.add_artist(self.obj_collision)
else:
self.obj_collision.update({'center': [y,x], 'visible':True})
# self.obj_robot.set_data(self.turtle_loc)
# plt.pause(0.01)
示例4: draw_robot
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def draw_robot(self, ax):
x = to_index(self.current_pose.x, self.map_rows, self.xlim)
y = to_index(self.current_pose.y, self.map_cols, self.ylim)
# radius = self.map_rows*0.4/self.grid_rows
radius = self.cr_pixels # self.collision_radius / (self.xlim[1]-self.xlim[0]) * self.map_rows
theta = -self.current_pose.theta-np.pi/2
xdata = y, y+radius*3*np.cos(theta)
ydata = x, x+radius*3*np.sin(theta)
if self.obj_robot == None:
#self.obj_robot = ax.imshow(self.turtle_loc, alpha=0.5, cmap=plt.cm.binary)
# self.obj_robot = ax.imshow(self.turtle_loc, alpha=0.5, cmap=plt.cm.Reds,interpolation='nearest')
self.obj_robot = Wedge((y,x), radius, 0, 360, color='r',alpha=0.5)
self.obj_heading, = ax.plot(xdata, ydata, 'r', alpha=0.5)
ax.add_artist(self.obj_robot)
else:
self.obj_robot.update({'center': [y,x]})
self.obj_heading.update({'xdata':xdata, 'ydata':ydata})
# self.obj_robot.set_data(self.turtle_loc)
# plt.pause(0.01)
示例5: draw_bel
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def draw_bel(self, ax):
o_bel,i_bel,j_bel = np.unravel_index(np.argmax(self.belief.cpu().detach().numpy(), axis=None), self.belief.shape)
x_bel = to_real(i_bel, self.xlim,self.grid_rows)
y_bel = to_real(j_bel, self.ylim,self.grid_cols)
x = to_index(x_bel, self.map_rows, self.xlim)
y = to_index(y_bel, self.map_cols, self.ylim)
# radius = self.map_rows*0.4/self.grid_rows
radius = self.cr_pixels # self.collision_radius / (self.xlim[1]-self.xlim[0]) * self.map_rows
theta = o_bel * self.heading_resol
theta = -theta-np.pi/2
xdata = y, y+radius*3*np.cos(theta)
ydata = x, x+radius*3*np.sin(theta)
if self.obj_robot_bel == None:
#self.obj_robot = ax.imshow(self.turtle_loc, alpha=0.5, cmap=plt.cm.binary)
# self.obj_robot = ax.imshow(self.turtle_loc, alpha=0.5, cmap=plt.cm.Reds,interpolation='nearest')
self.obj_robot_bel = Wedge((y,x), radius*0.95, 0, 360, color='b',alpha=0.5)
self.obj_heading_bel, = ax.plot(xdata, ydata, 'b', alpha=0.5)
ax.add_artist(self.obj_robot_bel)
else:
self.obj_robot_bel.update({'center': [y,x]})
self.obj_heading_bel.update({'xdata':xdata, 'ydata':ydata})
示例6: _draw_nucleotide_keys
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def _draw_nucleotide_keys(keys_required: Optional[List[str]],
keys_optional: Optional[List[str]],
center: Sequence[float],
nucleotide_body_patch: patches.Circle,
subplot: plt_axes.Subplot,
color, radius=10.0, width=5.0,
theta_min=0, theta_max=180):
# pylint: disable=too-many-arguments
# not possible to have less arguments without more complexity
# pylint: disable=too-many-locals
# is not possible to split the method without more complexity
keys_required = keys_required or []
keys_optional = keys_optional or []
keys_all = keys_required + keys_optional
if not keys_all:
return None
number_of_keys = len(keys_all)
theta_delta = (theta_max - theta_min) / number_of_keys
thetas = np.arange(theta_min, theta_max, theta_delta)
key_patches = {}
for each_key, each_start_theta in zip(keys_all, thetas):
hatch = "x" if each_key in keys_optional else None
theta1 = each_start_theta
theta2 = theta1 + theta_delta
key_patch = patches.Wedge(
center, radius + width, theta1, theta2, width=width,
facecolor=color, hatch=hatch, edgecolor="white")
key_patches[each_key] = key_patch
text_object = _draw_key_text(
each_key, center, theta1, theta2, radius, width, subplot)
key_patch.add_callback(partial(
_nucleotide_key_text_callback,
text_object=text_object,
nucleotide_body_patch=nucleotide_body_patch))
subplot.add_patch(key_patch)
return key_patches
示例7: _is_full_circle_deg
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def _is_full_circle_deg(thetamin, thetamax):
"""
Determine if a wedge (in degrees) spans the full circle.
The condition is derived from :class:`~matplotlib.patches.Wedge`.
"""
return abs(abs(thetamax - thetamin) - 360.0) < 1e-12
示例8: _is_full_circle_rad
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def _is_full_circle_rad(thetamin, thetamax):
"""
Determine if a wedge (in radians) spans the full circle.
The condition is derived from :class:`~matplotlib.patches.Wedge`.
"""
return abs(abs(thetamax - thetamin) - 2 * np.pi) < 1.74e-14
示例9: get_points
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def get_points(self):
# docstring inherited
if self._invalid:
points = self._viewLim.get_points().copy()
# Scale angular limits to work with Wedge.
points[:, 0] *= 180 / np.pi
if points[0, 0] > points[1, 0]:
points[:, 0] = points[::-1, 0]
# Scale radial limits based on origin radius.
points[:, 1] -= self._originLim.y0
# Scale radial limits to match axes limits.
rscale = 0.5 / points[1, 1]
points[:, 1] *= rscale
width = min(points[1, 1] - points[0, 1], 0.5)
# Generate bounding box for wedge.
wedge = mpatches.Wedge(self._center, points[1, 1],
points[0, 0], points[1, 0],
width=width)
self.update_from_path(wedge.get_path())
# Ensure equal aspect ratio.
w, h = self._points[1] - self._points[0]
deltah = max(w - h, 0) / 2
deltaw = max(h - w, 0) / 2
self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])
self._invalid = 0
return self._points
示例10: _gen_axes_patch
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def _gen_axes_patch(self):
return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0)
示例11: test_wedge_movement
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def test_wedge_movement():
param_dict = {'center': ((0, 0), (1, 1), 'set_center'),
'r': (5, 8, 'set_radius'),
'width': (2, 3, 'set_width'),
'theta1': (0, 30, 'set_theta1'),
'theta2': (45, 50, 'set_theta2')}
init_args = dict((k, v[0]) for (k, v) in six.iteritems(param_dict))
w = mpatches.Wedge(**init_args)
for attr, (old_v, new_v, func) in six.iteritems(param_dict):
assert_equal(getattr(w, attr), old_v)
getattr(w, func)(new_v)
assert_equal(getattr(w, attr), new_v)
示例12: test_wedge_range
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def test_wedge_range():
ax = plt.axes()
t1 = 2.313869244286224
args = [[52.31386924, 232.31386924],
[52.313869244286224, 232.31386924428622],
[t1, t1 + 180.0],
[0, 360],
[90, 90 + 360],
[-180, 180],
[0, 380],
[45, 46],
[46, 45]]
for i, (theta1, theta2) in enumerate(args):
x = i % 3
y = i // 3
wedge = mpatches.Wedge((x * 3, y * 3), 1, theta1, theta2,
facecolor='none', edgecolor='k', lw=3)
ax.add_artist(wedge)
ax.set_xlim([-2, 8])
ax.set_ylim([-2, 9])
示例13: get_points
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def get_points(self):
if self._invalid:
points = self._viewLim.get_points().copy()
# Scale angular limits to work with Wedge.
points[:, 0] *= 180 / np.pi
if points[0, 0] > points[1, 0]:
points[:, 0] = points[::-1, 0]
# Scale radial limits based on origin radius.
points[:, 1] -= self._originLim.y0
# Scale radial limits to match axes limits.
rscale = 0.5 / points[1, 1]
points[:, 1] *= rscale
width = min(points[1, 1] - points[0, 1], 0.5)
# Generate bounding box for wedge.
wedge = mpatches.Wedge(self._center, points[1, 1],
points[0, 0], points[1, 0],
width=width)
self.update_from_path(wedge.get_path())
# Ensure equal aspect ratio.
w, h = self._points[1] - self._points[0]
if h < w:
deltah = (w - h) / 2.0
deltaw = 0.0
elif w < h:
deltah = 0.0
deltaw = (h - w) / 2.0
else:
deltah = 0.0
deltaw = 0.0
self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]])
self._invalid = 0
return self._points
示例14: draw_center
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def draw_center(self, ax):
x = to_index(0, self.map_rows, self.xlim)
y = to_index(0, self.map_cols, self.ylim)
# radius = self.map_rows*0.4/self.grid_rows
radius = self.cr_pixels # self.collision_radius / (self.xlim[1]-self.xlim[0]) * self.map_rows
theta = 0-np.pi/2
xdata = y, y+radius*3*np.cos(theta)
ydata = x, x+radius*3*np.sin(theta)
obj_robot = Wedge((y,x), radius, 0, 360, color='r',alpha=0.5)
obj_heading, = ax.plot(xdata, ydata, 'r', alpha=0.5)
ax.add_artist(obj_robot)
示例15: _gen_axes_patch
# 需要导入模块: from matplotlib import patches [as 别名]
# 或者: from matplotlib.patches import Wedge [as 别名]
def _gen_axes_patch(self):
return Wedge((0.5, 0.5), 0.5, 270, 360)