事件名稱 | 類 | 描述 |
---|---|---|
‘button_press_event' | MouseEvent | 鼠標(biāo)按鍵被按下 |
‘button_release_event' | MouseEvent | 鼠標(biāo)按鍵被釋放 |
‘draw_event' | DrawEvent | 畫布繪圖 |
‘key_press_event' | KeyEvent | 鍵盤按鍵被按下 |
‘key_release_event' | KeyEvent | 鍵盤按鍵被釋放 |
‘motion_notify_event' | MouseEvent | 鼠標(biāo)移動 |
‘pick_event' | PickEvent | 畫布中的對象被選中 |
‘resize_event' | ResizeEvent | 圖形畫布大小改變 |
‘scroll_event' | MouseEvent | 鼠標(biāo)滾輪被滾動 |
‘figure_enter_event' | LocationEvent | 鼠標(biāo)進(jìn)入新的圖形 |
‘figure_leave_event' | LocationEvent | 鼠標(biāo)離開圖形 |
‘a(chǎn)xes_enter_event' | LocationEvent | 鼠標(biāo)進(jìn)入新的軸域 |
‘a(chǎn)xes_leave_event' | LocationEvent | 鼠標(biāo)離開軸域 |
因?yàn)閙atplotlib中用到的事件類都繼承自matplotlib.backend_bases.Event,所以所有事件都擁有以下3個共同屬性。
name:事件名稱。
canvas:生成事件的canvas對象。
guiEvent:觸發(fā)matplotlib事件的GUI事件,默認(rèn)為None。
所有事件均定義在matplotlib.backend_bases模塊中,其中常用的鼠標(biāo)事件MouseEvent、鍵盤事件KeyEvent都繼承自LocationEvent事件。LocationEvent事件有5個屬性。
鍵盤事件KeyEvent除繼承自LocationEvent事件的5個屬性外,還有1個key屬性,表示按下的鍵,值范圍為:None、任何字符、'shift'、win或者control。
鼠標(biāo)事件MouseEvent 除繼承自LocationEvent事件的5個屬性外,還有以下屬性
鼠標(biāo)點(diǎn)擊畫線,將鼠標(biāo)點(diǎn)擊相鄰兩點(diǎn)用直線連接,起始點(diǎn)為0,0。
from matplotlib import pyplot as plt class LineBuilder: def __init__(self, line): self.line = line self.xs = list(line.get_xdata()) self.ys = list(line.get_ydata()) self.cid = line.figure.canvas.mpl_connect('button_press_event', self) def __call__(self, event): print('click', event) if event.inaxes!=self.line.axes: return self.xs.append(event.xdata) self.ys.append(event.ydata) self.line.set_data(self.xs, self.ys) self.line.figure.canvas.draw() fig = plt.figure() ax = fig.add_subplot(111) ax.set_title('click to build line segments') line, = ax.plot([0], [0]) # empty line linebuilder = LineBuilder(line) plt.show()
到此這篇關(guān)于matplotlib事件處理基礎(chǔ)(事件綁定、事件屬性)的文章就介紹到這了,更多相關(guān)matplotlib 事件處理內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
標(biāo)簽:廊坊 臨汾 德宏 長春 河池 漢中 重慶 東莞
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《matplotlib事件處理基礎(chǔ)(事件綁定、事件屬性)》,本文關(guān)鍵詞 matplotlib,事件,處理,基礎(chǔ),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。