In [49]:
import math
from matplotlib import cm as cm
from matplotlib import pyplot as plt
import numpy as np
xmax = -3.14
xmin = 3.14
ymin = -2
ymax = 2
xs = np.linspace(xmin, xmax, num=200)
ys = np.linspace(ymin, ymax, num=200)
zs = [ [x + 1.0j*y for x in xs] for y in ys]
zs = np.array(zs)
image = np.abs(np.sin(zs))
In [53]:
im = plt.imshow(image, extent=[xmin, xmax, ymin, ymax], aspect='equal')
plt.xlabel('x')
plt.ylabel('y')
plt.title('plot of abs(sin(x+i*y))')
plt.show()
In [54]:
# plot a horizontal slice of the image
hor_slice = image[50, :]
plt.plot(xs, hor_slice)
plt.show()
In [55]:
# plot a vertical slice of the image
ver_slice = image[:, 50]
plt.plot(ys, ver_slice)
plt.show()
In [45]:
# sum values along the y-axis and plot a vertical slice of the image
y_sum = image.sum(axis=0)
plt.plot(xs, y_sum)
plt.show()
In [46]:
# sum values along the y-axis and plot a vertical slice of the image
x_sum = image.sum(axis=1)
plt.plot(ys, x_sum)
plt.show()
In [58]:
# extract a horizonal slice of width 10
hor_slice = image[50:100, :]
plt.imshow(hor_slice, extent=[xmin, xmax, ys[50], ys[100]], aspect='equal')
plt.show()
# take vertical sum along the slice
hor_slice_sum = hor_slice.sum(axis=0)
plt.plot(xs, hor_slice_sum)
plt.show()
In [ ]: