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 process_selected() 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 instance. The line should already be added to some matplotlib.axes.Axes instance 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\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>})
__init__(self, line)[source]

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

__module__ = 'matplotlib.lines'
__weakref__

list of weak references to the object (if defined)

onpick(self, event)[source]

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

process_selected(self, 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.

Examples using matplotlib.lines.VertexSelector