當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。