0

I'd like to use matplotlib for interactive drawing. I trained a neural network to approximate a distribution and I want to manually see if it is correct. Hence, once the computation is done I want to:

  • Mouse my mouse on the window. The pointer should be followed by a point (plt.scatter)

  • Get coordinates of the mouse and send them to my network

  • Using output from network, change the color of the point

Any leads I could follow ?

Thanks !!

Mounsif Mehdi
  • 83
  • 1
  • 7

1 Answers1

0

Matplotlib has a general event-handling API which should work for all GUI backends which is documented here. The event you want is called "motion_notify".

Here's an example (run it and the move the mouse around the plot window - mouse information will be printed in the terminal):

#!/usr/bin/env python3

from matplotlib import pyplot as plt
import numpy as np

fig, ax = plt.subplots()
ax.plot(np.random.rand(10))

def onmotion(event):
    print('%s dblclick: button=%s, x=%s, y=%s, xdata=%s, ydata=%s' %
          (event.dblclick, event.button,
           event.x, event.y, event.xdata, event.ydata))

cid = fig.canvas.mpl_connect('motion_notify_event', onmotion)

plt.show()

If you are embedding matplotlib in a GUI framework then you should probably use the API of the framework.

Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14