Matplotlib / python access points

I have a time series data group with points every 5 seconds. That way, I can create a line graph and even smooth out the data in order to have a smoother plot. The question is, is there any way in matplotlib or something in python that will allow me to click on a valid point to do something? So, for example, I could click on (10, 75) if this anchor point exists in my source data, and then I can do something in Python.

Any thoughts? Thank.

+3
source share
1 answer

To expand on what @tcaswell said, see the documentation here: http://matplotlib.org/users/event_handling.html

, :

import matplotlib.pyplot as plt

def on_pick(event):
    artist = event.artist
    xmouse, ymouse = event.mouseevent.xdata, event.mouseevent.ydata
    x, y = artist.get_xdata(), artist.get_ydata()
    ind = event.ind
    print 'Artist picked:', event.artist
    print '{} vertices picked'.format(len(ind))
    print 'Pick between vertices {} and {}'.format(min(ind), max(ind)+1)
    print 'x, y of mouse: {:.2f},{:.2f}'.format(xmouse, ymouse)
    print 'Data point:', x[ind[0]], y[ind[0]]
    print

fig, ax = plt.subplots()

tolerance = 10 # points
ax.plot(range(10), 'ro-', picker=tolerance)

fig.canvas.callbacks.connect('pick_event', on_pick)

plt.show()

, , ( , ax.plot vs. ax.scatter vs. ax.imshow?).

. event.artist event.mouseevent. , (, Line2D s, Collections ..), , event.ind.

, . http://matplotlib.org/examples/event_handling/lasso_demo.html#event-handling-example-code-lasso-demo-py

+6

Source: https://habr.com/ru/post/1599238/


All Articles