เพื่อบันทึก Array เป็นภาพ Grayscale ด้วย Matplotlib/numpy
- ตั้งค่าขนาดรูปและ padding ระหว่าง subplots
- สร้างข้อมูลสุ่มขนาด 5x5
- ตั้ง colormap เป็น "gray"
- พลอตข้อมูลด้วย imshow()
- แสดงรูปด้วย show()
ตัวอย่าง
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True arr = np.random.rand(5, 5) plt.gray() plt.imshow(arr) plt.show()
ผลลัพธ์
