Python matplotlib animation of a constantly updated data feed

460 views Asked by At

I'm trying to make a satellite visualization tool using an animation in matplotlib. I want to plot a 5-image animation and then constantly update this animation every time a new image appears.

I could animate the last 5 images like this:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation

fig = plt.figure(figsize=(20,10),frameon=True,tight_layout=True)
ax = plt.subplot(111, frameon=False)


map = Basemap(projection='cyl',resolution = 'i', area_thresh = 0.1,llcrnrlon=-75, llcrnrlat=-42,\
    urcrnrlon=-36, urcrnrlat=-10)
map.drawlsmask(land_color='white', ocean_color='lightsteelblue', lakes=False)
map.drawcoastlines(color='grey')

map.drawcountries(color='grey')
map.drawparallels(np.arange(-80., 81., 10.), labels=[1,0,0,0], fontsize=10)
map.drawmeridians(np.arange(-180., 181., 10.), labels=[0,0,0,1], fontsize=10)
map.drawstates()
map.drawmapboundary()

imgs = []

im = map.imshow(sat1,cmap='Greys',vmin=190, vmax=300,origin='upper')
imgs.append([im])

im2 = map.imshow(sat2,cmap='Greys',vmin=190, vmax=300,origin='upper')
imgs.append([im2])

im3 = map.imshow(sat3,cmap='Greys',vmin=190, vmax=300,origin='upper')
imgs.append([im3])

im4 = map.imshow(sat4,cmap='Greys',vmin=190, vmax=300,origin='upper')
imgs.append([im4])

im5 = map.imshow(sat5,cmap='Greys',vmin=190, vmax=300,origin='upper')
imgs.append([im5])


ani = animation.ArtistAnimation(fig,imgs, interval=500)

plt.show()

I also could display one image and update the image with the newest one, using FuncAnimation. But how can I update the list that ArtistAnimation displays?

I need to del imgs[0] and append a new imshow. That way I will always display the latest 5 satellite images.

Is that possible?

1

There are 1 answers

0
deets On

matplotlib is not really suited for such a problem. The GR-framework could be what you are looking for: http://gr-framework.org/