# from __future__ import unicode_literals
# import matplotlib
# matplotlib.rcParams['text.usetex'] = True
# matplotlib.rcParams['text.latex.unicode'] = True




from matplotlib import rc
import matplotlib.pyplot as plt
from scitools.std import sqrt, pi, exp, linspace
import os








def f(x, m, s):
    return (1.0/(sqrt(2*pi)*s))*exp(-0.5*((x-m)/s)**2)



m=0
s_min = 0.2
s_max = 2
x = linspace(m -3*s_max, m + 3*s_max, 100)
s_values = linspace(s_max, s_min, 5)
# f is max for x=m; smaller s gives larger max value
max_f = f(m, m, s_min)


os.system("rm ./tmp*.png")
#plt.figure(1, figsize=(6, 4))

#
#
plt.ion()
y = f(x, m, s_max)
# Make a first plot
lines = plt.plot(x, y)

rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.axis([x[0], x[-1], -0.1, max_f])
plt.xlabel(r'$x_1$', fontsize=16, color='k')
plt.ylabel(r'f',fontsize=16, color='k')
#plt.subplots_adjust(bottom=0.8)

#plt.show()
# Show the movie, and make hardcopies of frames simulatenously
counter = 0
for s in s_values:
        y = f(x, m, s)
        lines[0].set_ydata(y)
        plt.legend(['s=%4.2f' % s])
        plt.draw()
        plt.savefig('tmp_%04d.png' % counter, dpi=900)
        counter += 1

os.system("convert -delay 4 tmp_*.png movie.gif")
#raw_input('Press the Return key to quit: ')
# A gif can be created using ImageMagic
#convert -delay 4 tmp_*.png movie.gif

