本文整理汇总了Python中matplotlib.patches.PathPatch.remove方法的典型用法代码示例。如果您正苦于以下问题:Python PathPatch.remove方法的具体用法?Python PathPatch.remove怎么用?Python PathPatch.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.PathPatch
的用法示例。
在下文中一共展示了PathPatch.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VerticalMarker
# 需要导入模块: from matplotlib.patches import PathPatch [as 别名]
# 或者: from matplotlib.patches.PathPatch import remove [as 别名]
class VerticalMarker(QObject):
"""
An interactive marker displayed as a vertical line.
"""
x_moved = Signal(float)
def __init__(self, canvas, color, x, y0=None, y1=None, line_width=1.0, picker_width=5, line_style='-'):
"""
Init the marker.
:param canvas: A MPL canvas.
:param color: An MPL colour value
:param x: The x coordinate (data) of the marker.
:param y0: The y coordinate (data) of the bottom end of the marker. Default is None which means dynamically
set it to the current lowest y value displayed.
:param y1: The y coordinate (data) of the top end of the marker. Default is None which means dynamically
set it to the current highest y value displayed.
:param line_width: The line width (pixels).
:param picker_width: The picker sensitivity (pixels).
:param line_style: An MPL line style value.
"""
super(VerticalMarker, self).__init__()
self.ax = canvas.figure.get_axes()[0]
self.x = x
self.y0 = y0
self.y1 = y1
y0, y1 = self._get_y0_y1()
path = Path([(x, y0), (x, y1)], [Path.MOVETO, Path.LINETO])
self.patch = PathPatch(path, facecolor='None', edgecolor=color, picker=picker_width,
linewidth=line_width, linestyle=line_style, animated=True)
self.ax.add_patch(self.patch)
self.is_moving = False
def _get_y0_y1(self):
"""
Calculate the current y coordinates of the line ends.
:return: Tuple y0, y1.
"""
if self.y0 is None or self.y1 is None:
y0, y1 = self.ax.get_ylim()
if self.y0 is not None:
y0 = self.y0
if self.y1 is not None:
y1 = self.y1
return y0, y1
def remove(self):
"""
Remove this marker from the canvas.
"""
self.patch.remove()
def redraw(self):
"""
Redraw this marker.
"""
y0, y1 = self._get_y0_y1()
vertices = self.patch.get_path().vertices
vertices[0] = self.x, y0
vertices[1] = self.x, y1
self.ax.draw_artist(self.patch)
def get_x_in_pixels(self):
"""
Get the x coordinate in screen pixels.
"""
x_pixels, _ = self.patch.get_transform().transform((self.x, 0))
return x_pixels
def is_above(self, x, y):
"""
Check if a mouse positioned at (x, y) is over this marker.
:param x: An x mouse coordinate.
:param y: An y mouse coordinate.
:return: True or False.
"""
x_pixels, y_pixels = self.patch.get_transform().transform((x, y))
if self.y0 is not None and y < self.y0:
return False
if self.y1 is not None and y > self.y1:
return False
return abs(self.get_x_in_pixels() - x_pixels) < 3
def mouse_move_start(self, x, y):
"""
Start moving this marker if (x, y) is above it. Ignore otherwise.
:param x: An x mouse coordinate.
:param y: An y mouse coordinate.
"""
self.is_moving = self.is_above(x, y)
def mouse_move_stop(self):
"""
Stop moving.
"""
self.is_moving = False
def mouse_move(self, x, y=None):
"""
Move this marker to a new position if movement had been started earlier by a call to mouse_move_start(x, y)
#.........这里部分代码省略.........