I use ipython notebook (with the magic %matplotlib nbagg
). I was reviewing the matplotlib.widget.Cursor
but the cursor is only viewed widgets.Cursor. So I'd like to select two points clicking in the plot and get the initial and final x,y-position (e.g. time vs Temperature, selecting to points must return initial and final time). I need it for selecting manually an arbitrary interval. I think it's similar to get global x,y position, but I didn't understand well in that post.
How can I get a (x,y) position pointing with mouse in a interactive plot (Python)?
Obs. Something similar to CURSOR Procedure in IDL
Event handling should work.
import matplotlib.pylab as plt
import numpy as np
f,a = plt.subplots()
x = np.linspace(1,10,100)
y = np.sin(x)
a.plot(x,y)
pos = []
def onclick(event):
pos.append([event.xdata,event.ydata])
f.canvas.mpl_connect('button_press_event', onclick)
f.show()
On each click the current cursor position is appended to pos.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With