From: John H. <jdh...@ac...> - 2005-04-12 15:29:36
|
>>>>> "Sajec," == Sajec, Mike TQO <ms...@tq...> writes: Sajec,> Is there a simple way to grab x,y coordinates from active Sajec,> plot in a manner similar to using matlab's ginput() Sajec,> function? It depends on what you mean by simple :-) matplotlib provides a GUI independent way to capture basic events, eg to get the mouse coordinates in screen and data units and button clicks, key presses, etc. See http://matplotlib.sourceforge.net/tutorial.html#events Some people do not find callbacks intuitive. If you are one of these people, you might try something like the following from pylab import * class MouseMonitor: event = None def __call__(self, event): self.event = event mouse = MouseMonitor() connect('button_press_event', mouse) plot([1,2,3]) Now you can click on the plot, and get the coords like so print mouse.event.xdata, mouse.event.ydata See http://matplotlib.sourceforge.net/matplotlib.backend_bases.html#MouseEvent for more information on the mouse event attributes There are a couple of demos for event handling examples/keypress_demo.py examples/coords_demo.py JDH |