wxpythonでmatplotlibのクリック座標取得

wxpythonでmatplotlibのポイント座標取得 - メグタンの何でもブログ の続き

wxpythonでmatplotlibのイベント処理

Matplotlibのイベントには次のようなものがある。

Event name class Description
'button_press_event' MouseEvent mouse button is pressed
'button_release_event' MouseEvent mouse button is released
'close_event' CloseEvent figure is closed
'draw_event' DrawEvent canvas has been drawn (but screen widget not updated yet)
'key_press_event' KeyEvent key is pressed
'key_release_event' KeyEvent key is released
'motion_notify_event' MouseEvent mouse moves
'pick_event' PickEvent artist in the canvas is selected
'resize_event' ResizeEvent figure canvas is resized
'scroll_event' MouseEvent mouse scroll wheel is rolled
'figure_enter_event' LocationEvent mouse enters a new figure
'figure_leave_event' LocationEvent mouse leaves a figure
'axes_enter_event' LocationEvent mouse enters a new axes
'axes_leave_event' LocationEvent mouse leaves an axes

詳しくは次を見る
Event handling and picking — Matplotlib 3.5.3 documentation

wxpythonでmatplotlibの座標を取得する例

    self.fig.canvas.mpl_connect('button_press_event', self.on_button_press)
    def on_button_press(self, event):
        if event.inaxes!=self.ax: return
        if event.dblclick:
            t1 = 'double'
        else:
            t1 = 'single'
        t = t1 + ' click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (event.button, event.x, event.y, event.xdata, event.ydata)
        self.m_statusBar1.SetStatusText(t)

座標を取得してステータスバーに表示してみた例