gpt4 book ai didi

python - Matplotlib basemap 动画

转载 作者:行者123 更新时间:2023-11-28 20:46:14 24 4
gpt4 key购买 nike

我正在使用 basemap 在 map 上绘制一些点,并且我想向其中添加任何类型的动画。它实际上可以毫无用处,只要它是动画就很好。

这是我目前必须制作的 map ,

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0,
lat_0=0, lon_0=-130)
map.drawcoastlines()
map.drawcountries()
map.fillcontinents(color = 'gray')
map.drawmapboundary()
map.drawmeridians(np.arange(0, 360, 30))
map.drawparallels(np.arange(-90, 90, 30))

x,y = map(lons, lats)
map.plot(x, y, 'ro', markersize=4)


plt.show()

最佳答案

重写了 here 中的一些代码适合

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
my_map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0,
lat_0=0, lon_0=-130)
my_map.drawcoastlines()
my_map.drawcountries()
my_map.fillcontinents(color = 'gray')
my_map.drawmapboundary()
my_map.drawmeridians(np.arange(0, 360, 30))
my_map.drawparallels(np.arange(-90, 90, 30))

x,y = my_map(0, 0)
point = my_map.plot(x, y, 'ro', markersize=5)[0]

def init():
point.set_data([], [])
return point,

# animation function. This is called sequentially
def animate(i):
lons, lats = np.random.random_integers(-130, 130, 2)
x, y = my_map(lons, lats)
point.set_data(x, y)
return point,

# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(plt.gcf(), animate, init_func=init,
frames=20, interval=500, blit=True)

plt.show()

关于python - Matplotlib basemap 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21207513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com