Example #1
0
import matplotlib

matplotlib.use('Agg')  # graphics backend for hardcopy
from pylab import *

from JSAnimation import IPython_display
import JSAnimation_frametools as J

plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists

x = linspace(0., 10., 1001)
nsteps = 21
dt = 11. / (nsteps + 1)

plotdir = '_plots'

for n in range(nsteps + 1):
    t = n * dt
    x0 = x - 1. - t
    u = sin(20. * x0) * exp(-5. * x0**2)
    clf()
    plot(x, u, 'b')
    ylim(-1.2, 1.2)
    title('Wave packet at t = %8.4f' % t, fontsize=20)

    # Save this frame:
    J.save_frame(n, plotdir, verbose=False)
    #show()

anim = J.make_anim(plotdir)
Example #2
0
import matplotlib
matplotlib.use('Agg')

from pylab import *
import JSAnimation_frametools as J

plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists

input_data = loadtxt('input_data.txt')
n = int(input_data[0])
nterms = int(input_data[1])

x, f = loadtxt('xf.txt', unpack=True)

data = loadtxt('frames.txt')

terms = reshape(data[:,0], (n+2, nterms), order='F')
fsums = reshape(data[:,1], (n+2, nterms), order='F')

for k in range(nterms):
    term = terms[:,k]
    fsum = fsums[:,k]

    clf()
    subplot(2,1,1)
    plot(x,fsum,'b-')
    plot(x,f,'r-')
    title('Sum of first %s terms in Fourier series' % (k+1))
    axis([0,pi,-1.0,30.0])
Example #3
0
import matplotlib
matplotlib.use('Agg')
from matplotlib import image, animation
from matplotlib import pyplot as plt
import JSAnimation_frametools as J
from JSAnimation import IPython_display
import numpy as np
import glob

plotdir = '_plots'
J.make_plotdir(plotdir, clobber='true')
fid = open('input_data.txt')
n = int(fid.readline())
tfinal = float(fid.readline())
fid.readline()
nsteps = int(fid.readline())

ax = plt.axes(xlim=(0, np.pi), ylim=(-1, 1))
line, = ax.plot([], [], lw=2)
line.set_data(range(n), range(n))

data = open('solution.txt')
for i in range(nsteps + 1):
    soln = []
    plt.clf()
    for j in range(n + 2):
        soln.append(float(data.readline()))
    plt.axes(xlim=(0, np.pi), ylim=(-1, 1))
    plt.plot(np.arange(0, np.pi, np.pi / (n + 2)), soln)
    plt.plot(np.arange(0, np.pi, np.pi / (n + 2)), soln, 'bo')
    t = "%.3f" % (i * tfinal / nsteps)
Example #4
0
import matplotlib
matplotlib.use('Agg') # graphics backend for hardcopy
from pylab import *

from JSAnimation import IPython_display
import JSAnimation_frametools as J

plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists

x = linspace(0., 10., 1001)
nsteps = 21
dt = 11. / (nsteps+1)

plotdir = '_plots'

for n in range(nsteps+1):
    t = n*dt
    x0 = x - 1. - t
    u = sin(20.*x0) * exp(-5.*x0**2)
    clf()
    plot(x,u,'b')
    ylim(-1.2, 1.2)
    title('Wave packet at t = %8.4f' % t, fontsize=20)
    
    # Save this frame:
    J.save_frame(n, plotdir,verbose=False)
    #show()

anim = J.make_anim(plotdir)
Example #5
0
import matplotlib
matplotlib.use('Agg')

from pylab import *
import JSAnimation_frametools as J

plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists

input_data = loadtxt('input_data.txt')
n = int(input_data[0])
nterms = int(input_data[1])

x, f = loadtxt('xf.txt', unpack=True)

data = loadtxt('frames.txt')

terms = reshape(data[:, 0], (n + 2, nterms), order='F')
fsums = reshape(data[:, 1], (n + 2, nterms), order='F')

for k in range(nterms):
    term = terms[:, k]
    fsum = fsums[:, k]

    clf()
    subplot(2, 1, 1)
    plot(x, fsum, 'b-')
    plot(x, f, 'r-')
    title('Sum of first %s terms in Fourier series' % (k + 1))
    axis([0, pi, -1.0, 30.0])