python - Matplotlib Nested Events -
so working on re-making gui in python data analysis done in matlab. 1 functionality need able @ particular plot of data , select part of plot background. using matplotlib plotting, , trying use mouse , keyboard events handle functionality.
my question, then, how can "activate" event, in case using mouse select background data, using keystroke event tell program mouse input.
to map out like:
press "ctrl+b" enter background selection mode then: click once grab leftmost x data click again grab rightmost x data disable click input
any suggestions?
for reference, here bit of attempt; "ctrl+b" part works, freezes after first click.
def background(event): print('button=%s, x=%d, y=%d, xdata=%f, ydata=%f' % (event.key, event.x, event.y, event.xdata, event.ydata)) if event.key == "ctrl+b": print("you clicked ctrl+b") xbounds = [] while len(xbounds) < 2: cid = fig.canvas.mpl_connect('button_press_event', onclick) def onclick(event): xbounds.append(event.x)
oops, figured out myself... while statement running indefinitely , causing python crash. switching while if solved problem.
Comments
Post a Comment