matplotlib.lines.VertexSelector

class matplotlib.lines.VertexSelector(line)[源代码]

基类:object

管理回调以维护选定顶点的列表 Line2D . 派生类应重写 process_selected() 用镐做点什么。

下面是一个用红色圆圈突出显示选定顶点的示例:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.lines as lines

class HighlightSelected(lines.VertexSelector):
    def __init__(self, line, fmt='ro', **kwargs):
        lines.VertexSelector.__init__(self, line)
        self.markers, = self.axes.plot([], [], fmt, **kwargs)

    def process_selected(self, ind, xs, ys):
        self.markers.set_data(xs, ys)
        self.canvas.draw()

fig, ax = plt.subplots()
x, y = np.random.rand(2, 30)
line, = ax.plot(x, y, 'bs-', picker=5)

selector = HighlightSelected(line)
plt.show()

用初始化类 Line2D 实例。该行应该已经添加到 matplotlib.axes.Axes 实例和应设置选取器属性。

__dict__ = mappingproxy({'__module__': 'matplotlib.lines', '__doc__': "\n Manage the callbacks to maintain a list of selected vertices for\n `.Line2D`. Derived classes should override\n :meth:`~matplotlib.lines.VertexSelector.process_selected` to do\n something with the picks.\n\n Here is an example which highlights the selected verts with red\n circles::\n\n import numpy as np\n import matplotlib.pyplot as plt\n import matplotlib.lines as lines\n\n class HighlightSelected(lines.VertexSelector):\n def __init__(self, line, fmt='ro', **kwargs):\n lines.VertexSelector.__init__(self, line)\n self.markers, = self.axes.plot([], [], fmt, **kwargs)\n\n def process_selected(self, ind, xs, ys):\n self.markers.set_data(xs, ys)\n self.canvas.draw()\n\n fig, ax = plt.subplots()\n x, y = np.random.rand(2, 30)\n line, = ax.plot(x, y, 'bs-', picker=5)\n\n selector = HighlightSelected(line)\n plt.show()\n\n ", '__init__': <function VertexSelector.__init__>, 'process_selected': <function VertexSelector.process_selected>, 'onpick': <function VertexSelector.onpick>, '__dict__': <attribute '__dict__' of 'VertexSelector' objects>, '__weakref__': <attribute '__weakref__' of 'VertexSelector' objects>, '__annotations__': {}})
__init__(line)[源代码]

用初始化类 Line2D 实例。该行应该已经添加到 matplotlib.axes.Axes 实例和应设置选取器属性。

__module__ = 'matplotlib.lines'
__weakref__

对象的弱引用列表(如果已定义)

onpick(event)[源代码]

拾取该行后,更新所选索引集。

process_selected(ind, xs, ys)[源代码]

默认的“什么都不做”实现 process_selected() 方法。

参数:
indint列表

选定顶点的索引。

XS,YS类数组

选定顶点的坐标。

使用实例 matplotlib.lines.VertexSelector