尝试对散点图进行动画处理,但输出为空图,没有错误消息

时间:2019-04-10 22:14:41

标签: python matplotlib animation scatter-plot matplotlib-basemap

我正在尝试制作一系列闪电风暴的动画,其目的是使每个动画帧在给定的时间间隔内显示雷击,而散射值将是闪电的电流。

但是,尽管我能够将整个数据集绘制为单个散点图,但是却无法对其进行动画处理。 我正在使用matplotlib中的动画模块

数据具有以下格式,位置示例array [0]对应于单个雷击

lat
Out[2]: array([39.983 , 39.782 , 39.947 , ..., 41.8225, 40.8884, 40.9198])

lon
Out[3]: array([11.8977, 11.8266, 11.9234, ...,  9.0467,  9.3044,  9.3147])

cur
Out[4]: array([  2.,   6.,   5., ..., -14., -19., -32.])

ltime
Out[5]: 
DatetimeIndex(['2018-08-20 00:39:09', '2018-08-20 00:39:10',
               '2018-08-20 00:39:12', '2018-08-20 00:39:18',
               '2018-08-20 00:39:19', '2018-08-20 00:39:19',
               '2018-08-20 00:39:26', '2018-08-20 00:39:27',
               '2018-08-20 00:39:27', '2018-08-20 00:39:27',
               ...
               '2018-08-20 10:44:15', '2018-08-20 10:44:15',
               '2018-08-20 10:44:34', '2018-08-20 10:44:42',
               '2018-08-20 10:45:01', '2018-08-20 10:45:01',
               '2018-08-20 10:45:01', '2018-08-20 10:45:08',
               '2018-08-20 10:45:24', '2018-08-20 10:45:24'],
              dtype='datetime64[ns]', length=1903, freq=None)

我的动画看起来像这样

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import matplotlib.animation as animation
import datetime as dt

m = Basemap(projection = 'mill',llcrnrlat = 30, urcrnrlat=60,\
            llcrnrlon= -10, urcrnrlon= 30,resolution='l')

m.drawcoastlines()
m.fillcontinents()
m.drawmapboundary()

# draw parallels and meridians.
parallels = np.arange(0.,181,1.)
m.drawparallels(parallels,labels=[False,False,True,False])
meridians = np.arange(0.,361.,1.)
meridians = m.drawmeridians(meridians,labels=[True,False,False,False])

"""
nedestående er animationen
"""
x,y = m(lon,lat)
col = cur
scat = plt.scatter(x, y, c=col,marker = 'o', s=20, alpha=1 ,cmap='seismic')
plt.clim(-50,50)
plt.colorbar();
plt.title('Lightning with current')

def init():
    return scat,

def animate(i):
    startP = ltime[0] + dt.timedelta(minutes=10*i)
    slutP = ltime[0] + dt.timedelta(minutes=10*(i+1))

    res = (slutP >= ltime) & (startP < ltime)

    x, y = m(lon[res], lat[res])
    scat.set_data(x, y)
    col = cur[res]
    scat.set_color(col)
    return scat,

anim = animation.FuncAnimation(plt.gcf(), animate, init_func=init,
                               frames=np.size(lat), interval=100, blit=True)

plt.show()

为了澄清,在默认设置每帧时间间隔的情况下,这在单独的绘图中起作用,而我仅绘制位置。

我希望动画散点图

但是我用颜色条获得了地图,但是没有雷击。

0 个答案:

没有答案