ในการแสดงข้อมูล Scalar 2D ด้วย matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้:
- ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
- เริ่มต้นตัวแปร N สำหรับตัวอย่างข้อมูล
- สร้างจุดข้อมูล x และ y ด้วย numpy
- รับเมทริกซ์พิกัดจากเวกเตอร์พิกัด
- รับจุดข้อมูล z ด้วย numpy
- สร้าง pseudocolor plot ด้วยกริดสี่เหลี่ยมไม่สม่ำเสมอ
- เพื่อแสดงรูป ใช้เมธอด show()
ตัวอย่าง
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True n = 256 x = np.linspace(-3., 3., n) y = np.linspace(-3., 3., n) X, Y = np.meshgrid(x, y) Z = X * np.sinc(X ** 2 + Y ** 2) plt.pcolormesh(X, Y, Z, cmap='copper', shading='flat') plt.show()
ผลลัพธ์

