Python 根据数据帧中的值设置箭袋打印动画

Python 根据数据帧中的值设置箭袋打印动画,python,animation,pandas,matplotlib,plot,Python,Animation,Pandas,Matplotlib,Plot,嗨,我正在尝试从我的数据帧中的数据制作一个箭袋图的动画 我有这样的数据存储在一个数据框中,有点像这样 QuivXLoc QuivYLoc QuivXVal QuivYVal QuivColorVal QuivPlotNum 0 -70.22 -127.241 1.624 -0.879 1.846623 1 1 -61.74 -127.241 -0.973 -0.027

嗨,我正在尝试从我的数据帧中的数据制作一个箭袋图的动画

我有这样的数据存储在一个数据框中,有点像这样

    QuivXLoc    QuivYLoc    QuivXVal    QuivYVal    QuivColorVal    QuivPlotNum
0   -70.22     -127.241     1.624       -0.879      1.846623        1
1   -61.74     -127.241     -0.973      -0.027      0.973375        1
2   -65.98     -121.835     0.046       2.416       2.416438        1
3   -74.46     -121.835     -0.151      2.673       2.677262        1
4   -78.70     -116.429     1.073       -0.954      1.435773        2
我现在正在这样绘制它,它会为每个序列号生成单独的图

for seq in quidf['QuivPlotNum'].unique():
    temp=quidf[quidf['QuivPlotNum']==seq]  ## make subset to plot
    plt.quiver(temp['QuivXLoc'], temp['QuivYLoc'], temp['QuivXVal'], temp['QuivYVal'],        # data
           temp['QuivColorVal'],                   # colour the arrows based on this array
           cmap=cm.jet,     # colour map
           headlength=3)        # length of the arrows
有一些额外的代码来格式化我遗漏的绘图

我想做的是在遍历数据帧中的序列号的基础上设置序列动画。我所看到的箭袋动画的所有例子都涉及到通过一些递增的标量来缩放之前的函数

我想生成的类似箭袋动画示例,我已经尝试过,但无法确定如何更改update\u quiver以适用于我的应用程序:

使用
matplotlib.animation
模块及其
FuncAnimation
类:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
import pandas as pd

# read in the date and group it by the frame number
data = pd.read_csv('data2.csv', index_col=0)
grouped = data.groupby('QuivPlotNum')

# set up the figure
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(-200, 200)
ax.set_ylim(-200, 200)

# create empty plot for the update function to manipulate
plot = ax.quiver([], [], [], [], [], cmap='jet', headlength=3)

# create an iterator over the group, next() will return a tuple
# of QuivPlotNum, DataFrame
iterator = iter(grouped)

def update(i):
    # get next thing in the iterator
    key, data = next(iterator)
    # set new x, y coordinates for the plot
    plot.set_offsets(np.column_stack([data.QuivXLoc, data.QuivYLoc]))
    # update vector and color values
    plot.set_UVC(data.QuivXVal, data.QuivYVal, data.QuivColorVal)

# create the animation, update every 1000 ms
ani = FuncAnimation(fig, update, interval=1000)

# show it
plt.show()

你的意思是使箭袋箭头的长度增加到最后的长度吗?你尝试过什么?是的,就像在这个例子中,动画显示了按帧变化的箭袋图。但它是基于标量更新的。我想根据数据框中存储的数据进行绘图。