1

I'm trying to write a function that allows me to pick a point in my polygon and change its coordinates as follows:

  1. choose a point p(i)
  2. associate it with the coordinates of the mouse then draw the changement
  3. the second click stores these coordinates at p(i)
import matplotlib as plt
import numpy as np
def mouve(event):
    fig=plt.gcf()
    ax=plt.gca()
    global poly

    cl=[]
    m = np.array( [event.xdata, event.ydata])
    print(m)
#global coords
   cl.append(m)
   ax.clear()
   M1=ax.plot(poly[:,0], poly[:,1], '-ro')
   plt.xlim([-10, 10])
   plt.ylim([-10, 10])
   fig.canvas.draw()
   plt.show()
   global cidd
   for i in range(len(poly)):
       if dist(m,poly[i])<1:
           poly[i]=m

   if (len(cl) > 2 and all(cl[-1,:]==X[-2,:])) :
       fig.canvas.mpl_disconnect(cidd)
       print('done')
    return poly

 def change(p):
%matplotlib qt
    global poly
    poly=p
    fig=plt.figure()
    ax = fig.add_subplot(111)
    plt.xlim([-10, 10])
    plt.ylim([-10, 10])
    ax.plot(poly[:,0], poly[:,1], '-bo')
    global cidd
    cidd=fig.canvas.mpl_connect('button_press_event', mouve)
    return poly

0 Answers0