Q7.5.1The two-dimensional sinc function
Generate an image plot of the sinc function in the Cartesian plane, \(\mathrm{sinc}(r) = \sin r / r\) where \(r = \sqrt{x^2+y^2}\).
Show solution
The following code uses np.hypot and np.sinc to calculate the function, and plot_surface with the summer colormap to produce the plot:
sinc2d
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x, y = np.linspace(-10, 10, 400), np.linspace(-10, 10, 400)
X, Y = np.meshgrid(x, y)
f = np.sinc(np.hypot(X, Y))
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.plot_surface(X, Y, f, rstride=5, cstride=5, cmap="summer", ec="k", lw=0.5)
ax.tick_params(axis="x", which="major", pad=-5)
ax.tick_params(axis="y", which="major", pad=-5)
plt.show()