当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python matplotlib VertexSelector用法及代码示例


本文简要介绍 python 语言中 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):
        super().__init__(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()
参数
line Line2D

该行必须已添加到 Axes 并且必须设置其选取器属性。

相关用法


注:本文由纯净天空筛选整理自skytowner.com大神的英文原创作品 matplotlib.lines.VertexSelector。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。