Copyright (C) 2010-2020 Luke Olson
Copyright (C) 2020 Andreas Kloeckner
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
import sympy as sym
sx = sym.Symbol("x")
sy = sym.Symbol("y")
sr = sym.sqrt(sx**2 + sy**2)
sphi = sym.atan2(sy, sx)
ssol = sr**2 * sym.cos(2*sphi)
sym.simplify(sym.diff(ssol, sx, 2) + sym.diff(ssol, sy, 2))
step = 0.04
maxval = 1.0
r = np.linspace(0, 1.25, 50)
p = np.linspace(0, 2*np.pi, 50)
R, P = np.meshgrid(r, p)
X, Y = R*np.cos(P), R*np.sin(P)
Z = R**2 * np.cos(2*P)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r,
linewidth=0, antialiased=False)
<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x7f8e188827d0>
For the domain (and any given subdomain):