November 2018
Beginner to intermediate
214 pages
5h 2m
English
To manipulate the data, we need to add an extra keyword argument called picker to our plot, as well as a new function called gravity as shown in the following points:
# Using pick_event & picker to move pointsplt.plot(np.random.rand(100), np.random.rand(100), 'ko', picker=5)def gravity(event): thispoint = event.artist ind = event.ind[0] xpos = thispoint.get_xdata() ypos = thispoint.get_ydata() # Calculate the distance to other particles, update their positions with a r^-2 law rpos = np.linalg.norm([xpos-xpos[ind],ypos-ypos[ind]], axis=0) thispoint.set_xdata(xpos - 1e-3*(xpos - xpos[ind])/(1e- 9+rpos*rpos)) ...
Read now
Unlock full access