matplotlib - python: submit variable to main program -


i have program below:

first,i plot picture:

fig=plt.figure(figsize=(7,6)) ax = fig.add_subplot(111) ax.plot(x,y,'ro') ax.set_title('click on points') plt.show() 

then when right-click picture.it zoom-in,and i'll pick 1 point on zoom-in picture:

def onclick(event):     print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(         event.button, event.x, event.y, event.xdata, event.ydata)     if event.button==3:         '''         function zoom-in         '''         plt.show()         onepoint = pylab.ginput(1) return true 

below command can call "onclick" function

cid= fig.canvas.mpl_connect('button_press_event', onclick) 

the qusetion "how can submit variable "onepoint" got in "onclick"function main program"

you use global variable. declare var outside function:

onepoint = 0 

and tell function using this:

def onclick(event):     global onepoint      print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(         event.button, event.x, event.y, event.xdata, event.ydata)     if event.button==3:         '''         function zoom-in         '''         plt.show()         onepoint = pylab.ginput(1)     return true 

any changes function makes variable affect globally.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -