``````

In [1]:

import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.animation as manimation

``````
``````

In [2]:

r = 1
r2 = r ** 2
c = 1.0

t0 = 0
tf = 0.5
dt = 0.01
t = np.arange(t0, tf+dt, dt)
len_t = len(t)

x0 = 0
xf = 1
dx = c * dt / r
x = np.arange(x0, xf+dx, dx)
len_x = len(x)

y0 = 0
yf = 1
dy = dx
y = np.arange(y0, yf+dy, dy)
len_y = len(y)

z = np.zeros((len(x), len(y), len(t)))
zc = np.zeros((len(x), len(y)))

zc[0, :] = np.ones(len(zc[0, :]))
zc[len(x)-1, :] = np.ones(len(zc[len(x)-1, :]))
zc[:, 0] = np.ones(len(zc[:, 0]))
zc[:, len(y)-1] = np.ones(len(zc[:, len(y)-1]))

``````
``````

In [3]:

k1 = 1000
k2 = 500
xc1 = 0.3
xc2 = 0.6

``````
``````

In [4]:

for i in range(1, len_x-1):
for j in range(1, len_y-1):
if(zc[i,j] != 1):
x_i = i * dx
y_i = j * dy
z[i, j, 0] = np.exp(-k1 * (x_i - xc1) ** 2) + np.exp(-k1 * (y_i - xc2) ** 2)

``````
``````

In [5]:

for k in range(0, len_t-1):
for i in range(0, len_x):
for j in range(0, len_y):
if zc[i,j] == 1:
continue
if k > 0:
zp = z[i,j,k-1]
else:
zp = 0
(t_i, x_i, y_i) = (k*dt, i*dx, j*dy)
z[i, j, k+1] = r2 * (z[i+1,j,k] + z[i-1,j, k] + z[i,j+1,k] + z[i, j-1, k]) - zp + 2*(1-2*r2)*z[i, j, k]
if k % 25 == 0:
print(len_t - k)

``````
``````

51
26

``````
``````

In [6]:

plt.matshow(z[:,:,])

plt.colorbar()
plt.show()

``````
``````

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-f79e1f95174a> in <module>()
----> 1 plt.matshow(z[:,:,])
2 plt.clim(-5, 5)
3 plt.colorbar()
4 plt.show()

/usr/lib/python3/dist-packages/matplotlib/pyplot.py in matshow(A, fignum, **kw)
2256         ax  = fig.add_axes([0.15, 0.09, 0.775, 0.775])
2257
-> 2258     im = ax.matshow(A, **kw)
2259     sci(im)
2260

/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py in matshow(self, Z, **kwargs)
6837         """
6838         Z = np.asanyarray(Z)
-> 6839         nr, nc = Z.shape
6840         kw = {'origin': 'upper',
6841               'interpolation': 'nearest',

ValueError: too many values to unpack (expected 2)

``````
``````

In [14]:

FFMpegWriter = manimation.writers['ffmpeg']
comment='Movie support!')

fig = plt.figure()

with writer.saving(fig, "writer_test.mp4", 60):
for i in range(len_t):
ax.matshow(z[:,:,i])
plt.clim(-5, 5)
writer.grab_frame()

``````
``````

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-8771e1de10a0> in <module>()
11     for i in range(len_t):
12         ax.matshow(z[:,:,i])
---> 13         plt.clim(-5, 5)
14         writer.grab_frame()

/usr/lib/python3/dist-packages/matplotlib/pyplot.py in clim(vmin, vmax)
2183     im = gci()
2184     if im is None:
-> 2185         raise RuntimeError('You must first define an image, eg with imshow')
2186
2187     im.set_clim(vmin, vmax)

RuntimeError: You must first define an image, eg with imshow

``````
``````

In [ ]:

``````
``````

In [ ]:

``````