ซ้อน contourf และ surface plot แบบ 3D
วาด contour plot และ surface plot บน axes 3D เดียวกัน
ขั้นตอน
- กำหนดตัวแปร delta, xrange, yrange, x, y ด้วย NumPy
- สร้าง figure ด้วย figure()
- ดึง axes 3D ด้วย projection='3d'
- สร้าง 3D contour plot ด้วยข้อมูล x, y
- วาด surface plot ด้วยข้อมูล x, y
- แสดงด้วย show()
ตัวอย่างโค้ด
from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True delta = 0.025 xrange = np.arange(-5.0, 20.0, delta) yrange = np.arange(-5.0, 20.0, delta) x, y = np.meshgrid(xrange, yrange) fig = plt.figure() ax = fig.gca(projection='3d') ax.contour(x, y, (np.sin(x) - np.cos(y)), [0]) ax.plot_surface(x, y, (np.sin(x) - np.cos(y)), cmap="afmhot_r") plt.show()
ผลลัพธ์
