本文簡要介紹 python 語言中matplotlib.backend_bases.FigureCanvasBase.mpl_connect
的用法。
-
將函數
func
綁定到事件s
。- 參數:
- s str
-
以下事件 ID 之一:
-
'button_press_event'
-
'button_release_event'
-
'draw_event'
-
'key_press_event'
-
'key_release_event'
-
'motion_notify_event'
-
'pick_event'
-
'resize_event'
-
'scroll_event'
-
'figure_enter_event',
-
'figure_leave_event',
-
'axes_enter_event',
-
'axes_leave_event'
-
'close_event'。
-
- func 可調用的
-
要執行的回調函數,必須有簽名:
def func(event: Event) -> Any
對於位置事件(按鈕和按鍵按下/釋放),如果鼠標位於 Axes 上,則該事件的
inaxes
屬性將設置為Axes
事件發生結束,此外,變量xdata
和ydata
屬性將設置為數據坐標中的鼠標位置。有關詳細信息,請參閱KeyEvent
和MouseEvent
。注意如果 func 是一個方法,則僅存儲對該方法的弱引用。因此,該圖不會影響關聯對象的生命周期。通常,您希望通過持有對對象的引用來確保對象在圖窗的整個生命周期中保持活動狀態。
- 返回:
- cid
-
可與
FigureCanvasBase.mpl_disconnect
一起使用的連接 ID。
例子
def on_press(event): print('you pressed', event.button, event.xdata, event.ydata) cid = canvas.mpl_connect('button_press_event', on_press)
用法
mpl_connect(s, func)
相關用法
- Python matplotlib FigureCanvasBase.mpl_disconnect用法及代碼示例
- Python matplotlib FigureCanvasBase.new_timer用法及代碼示例
- Python matplotlib Figure.set_size_inches用法及代碼示例
- Python matplotlib Figure.add_axes用法及代碼示例
- Python matplotlib FigureBase.subplots用法及代碼示例
- Python matplotlib FigureBase.align_ylabels用法及代碼示例
- Python matplotlib FigureBase.align_xlabels用法及代碼示例
- Python matplotlib FigureBase.add_axes用法及代碼示例
- Python matplotlib FigureMpl用法及代碼示例
- Python matplotlib FigureBase.legend用法及代碼示例
- Python matplotlib Figure.figimage用法及代碼示例
- Python matplotlib Figure.add_subplot用法及代碼示例
- Python matplotlib Figure.legend用法及代碼示例
- Python matplotlib FigureBase.sticky_edges用法及代碼示例
- Python matplotlib FigureBase.add_subplot用法及代碼示例
- Python matplotlib Figure.savefig用法及代碼示例
- Python matplotlib Figure.colorbar用法及代碼示例
- Python matplotlib Figure.add_gridspec用法及代碼示例
- Python matplotlib Figure.sticky_edges用法及代碼示例
- Python matplotlib FigureBase.colorbar用法及代碼示例
- Python matplotlib Figure.subplots用法及代碼示例
- Python matplotlib Figure.align_ylabels用法及代碼示例
- Python matplotlib Figure.align_xlabels用法及代碼示例
- Python matplotlib FigureBase.add_gridspec用法及代碼示例
- Python matplotlib FontManager用法及代碼示例
注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.backend_bases.FigureCanvasBase.mpl_connect。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。