I made a 'plotter(x)' function that reads a timeseries in a pd.DataFrame
and returns a figure (return fig
) made of two axes. One is a pyplot.figure.add_subplot(111)
, in which I add descartes.PolygonPatch(shapely.Polygon(y))
-es. The second one is a pyplot.figure.add_axes
, which includes a colorbar with a customized colormap.
I need a second function to produce a movie showing plots for each of the time-steps in the time-series at a rate of 2 fps. I did this:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def video_plotter(rain_series):
fig = plt.figure()
ims = []
for i in (range(len(rain_series.columns)-1)):
fig = plotter(rain_series[[rain_series.columns[i], rain_series.columns[-1]]])
ims.append([fig])
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,repeat_delay=1000)
writer = animation.MencoderFileWriter(fps=2)
ani.save('demo.mp4',writer=writer,dpi=100)
Question 1: What should I do to make this work?
I know an option is to loop over the time-series applying the function I already have to create a series of .png-s, and then use mencoder directly in the unix terminal to create an .avi. However the colorbar, and most of the values of shapely polygons being mapped, do not change over time, and consume a lot computation each time they need to be drawn. Additionally, I need to add a mpl_toolkits.basemap.Basemap
that does not change either. This makes this '.png-series' approach inconvenient. I also can not use sys
imports: I need to do everything within Python.
I need to use blit=True
in matplotlib.animation to avoid redrawing features if they are the same in the precedent frame. Does it also apply for basemaps?
Question 2: How can I integrate a static basemap in the video?