matplotlib.lines.VertexSelector

class matplotlib.lines.VertexSelector(line)[source]

Bases: object

Manage the callbacks to maintain a list of selected vertices for Line2D. Derived classes should override the process_selected method to do something with the picks.

Here is an example which highlights the selected verts with red circles:

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()

Initialize the class with a Line2D. The line should already be added to an Axes and should have the picker property set.

__dict__ = mappingproxy({'__module__': 'matplotlib.lines', '__doc__': "\n    Manage the callbacks to maintain a list of selected vertices for `.Line2D`.\n    Derived classes should override the `process_selected` method 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)[source]

Initialize the class with a Line2D. The line should already be added to an Axes and should have the picker property set.

__module__ = 'matplotlib.lines'
__weakref__

list of weak references to the object (if defined)

onpick(event)[source]

When the line is picked, update the set of selected indices.

process_selected(ind, xs, ys)[source]

Default "do nothing" implementation of the process_selected method.

Parameters:
indlist of int

The indices of the selected vertices.

xs, ysarray-like

The coordinates of the selected vertices.