#98 Making a movie of a plot
Consider Gaussian bell function.
import matplotlib.pyplot as plt import numpy as np import os os.chdir(r'D:\projects\wordpress\ex99') os.getcwd() def f(x, m, s): return (1.0/(np.sqrt(2*np.pi)*s))*np.exp(-0.5*((x-m)/s)**2) m = 0; s_start = 2; s_stop = 0.2 s_values = np.linspace(s_start, s_stop, 50) #number of png files x = np.linspace(m -3*s_start, m + 3*s_start, 1000) # f is max for x=m (smaller s gives larger max value) max_f = f(m, m, s_stop) y = f(x,m,s_stop) lines = plt.plot(x,y) plt.axis([x[0], x[-1], -0.1, max_f]) plt.xlabel('x') plt.ylabel('f') frame_counter = 0 for s in s_values: y = f(x, m, s) lines[0].set_ydata(y) #update plot data and redraw plt.draw() plt.savefig(f'tmp_{frame_counter:03d}.png',dpi=300) #unique filename frame_counter += 1
Install programm ffmpeg for Windows and run the following command:
ffmpeg -f image2 -i D:/projects/wordpress/ex99/tmp_%03d.png movie.mpg
Recent Comments