Python Matplotlib Get Data With Cursor From Plot
, Hi guys, I'm using python>matplotlib and I want to get the data from the plot by using the cursor. import numpy as np import matplotlib.pyplot as plt t = np.arange(0., 2., 0.1
Solution 1:
There is a Picker example on the matplotlib page. You can adapt it to show the first n point pairs when the nth point is clicked.
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0., 2., 0.1)
line, = plt.plot(t,t,'g^', picker=6)
def click(event):
artist = event.artist
ind = event.ind[0]
xd = artist.get_xdata()[:ind]
yd = artist.get_ydata()[:ind]
print( zip(xd, yd) )
cid = plt.gcf().canvas.mpl_connect("pick_event", click)
plt.show()
Post a Comment for "Python Matplotlib Get Data With Cursor From Plot"