Search code examples
matplotlibanimationcoordinatestimeserieschart

How can i make a quiver or stream plot based on DeltaX and DeltaY


I have a data set like this. I would like to make a quiver or stream plot based location, direction and time. Columns X and Y are the location of a person, ID 42386. Columns xx and yy are the directions/differences of these locations based on the earlier observation, indicating the direction the person moves. How can I use these columns to make a quiver or stream plot based on time?

         ID                     Time    X    Y   xx   yy 
62283  42386  2019-07-24 08:48:53.039  259  243 -1.0 -2.0
62286  42386  2019-07-24 08:48:53.280  260  242  1.0 -1.0
62289  42386  2019-07-24 08:48:53.531  258  243 -2.0  1.0
62292  42386  2019-07-24 08:48:53.721  259  241  1.0 -2.0
62295  42386  2019-07-24 08:48:54.073  263  243  4.0  2.0
62298  42386  2019-07-24 08:48:54.215  263  243  0.0  0.0
62301  42386  2019-07-24 08:48:54.555  266  242  3.0 -1.0
62304  42386  2019-07-24 08:48:54.806  268  242  2.0  0.0
62307  42386  2019-07-24 08:48:55.040  268  241  0.0 -1.0
62310  42386  2019-07-24 08:48:55.285  267  240 -1.0 -1.0
62313  42386  2019-07-24 08:48:55.533  268  242  1.0  2.0
62316  42386  2019-07-24 08:48:55.812  268  242  0.0  0.0
62319  42386  2019-07-24 08:48:56.040  267  241 -1.0 -1.0
62322  42386  2019-07-24 08:48:56.272  267  241  0.0  0.0
62325  42386  2019-07-24 08:48:56.483  267  241  0.0  0.0
62328  42386  2019-07-24 08:48:56.747  267  242  0.0  1.0
62331  42386  2019-07-24 08:48:57.072  266  240 -1.0 -2.0
62334  42386  2019-07-24 08:48:57.320  267  241  1.0  1.0
62337  42386  2019-07-24 08:48:57.559  267  240  0.0 -1.0
62340  42386  2019-07-24 08:48:57.717  267  240  0.0  0.0
62343  42386  2019-07-24 08:48:58.044  266  243 -1.0  3.0
62346  42386  2019-07-24 08:48:58.306  266  243  0.0  0.0
62349  42386  2019-07-24 08:48:58.536  267  243  1.0  0.0
62352  42386  2019-07-24 08:48:58.839  267  243  0.0  0.0
62355  42386  2019-07-24 08:48:59.006  267  243  0.0  0.0
62358  42386  2019-07-24 08:48:59.264  267  241  0.0 -2.0
62361  42386  2019-07-24 08:48:59.498  264  239 -3.0 -2.0
62364  42386  2019-07-24 08:48:59.735  262  237 -2.0 -2.0

Solution

  • How about:

    plt.figure(figsize=(12,8))
    plt.quiver(df.X, df.Y, df.xx.shift(-1), df.yy.shift(-1))
    plt.plot(df.X, df.Y)
    

    Output:

    enter image description here