我正在尝试使用Numpy为底图上的一些箭数设置动画,但数据是在不同的文件上(E和N gps位移)。首先,我尝试用np.loadtxt和glob加载所有文件,结果它是这种风格的数组(或矩阵,此时我不知道):
bla = [array([1,2,3,....,1000]), array([1,2,3,....,1000]),....]
我想要的是在底图中为gps数据移位的动画设置动画,为此我制作了这段代码:
import numpy as np
from glob import glob
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import matplotlib.animation as animation
estaE = glob('/Users/joaquinjulve/Documents/Universidad/Herramientas/Examen/GPS_E/*e.out')
gpsE = [np.loadtxt(a) for a in estaE]
estaN = glob('/Users/joaquinjulve/Documents/Universidad/Herramientas/Examen/GPS_N/*n.out')
gpsN = [np.loadtxt(b) for b in estaN]
estaciones = np.loadtxt('/Users/joaquinjulve/Documents/Universidad/Herramientas/Examen/estaciones.coord.out', usecols=(1,2))
gpsupE = np.asarray(gpsE)
gpsupN = np.asarray(gpsN)
desE = [a.T[1] for a in gpsE]
desN = [b.T[1] for b in gpsN]
t = [c.T[0]for c in gpsE]
tup = np.asarray(t)
desupE = np.asarray(desE)
desupN = np.asarray(desN)
map = Basemap(projection='merc',
llcrnrlat=-45, llcrnrlon=-75,
urcrnrlat=-25, urcrnrlon=-60, resolution=None)
map.drawparallels(np.arange(-90,90.,4), labels=[1,0,0,0])
map.drawmeridians(np.arange(-180,180,4), labels=[0,0,0,1])
map.bluemarble(scale=4)
lat = estaciones.T[0]
lon = estaciones.T[1]
x, y = map(lon, lat)
Q = map.quiver(x, y, desupE, desupN, color='red')
def update_quiver(Q, x, y):
U = desupE
V = desupN
Q.set_UVC(U,V)
anim = animation.FuncAnimation(map, update_quiver, fargs=(Q, x, y),
interval=10, blit=True)
plt.show()