การเข้าถึงหมายเลข Figure ปัจจุบัน
ใช้ plt.gcf().number เพื่อดึงหมายเลขของ figure ที่กำลังใช้งานอยู่
ขั้นตอนหลัก
- สร้าง figure ด้วย figure(count) โดยระบุหมายเลขหรือชื่อหน้าต่าง
- ดึงหมายเลข figure ปัจจุบันด้วย plt.gcf().number
ตัวอย่างโค้ด
from matplotlib import pyplot as plt
fig = plt.figure(3)
print("Number of figures: ", plt.gcf().number)
ผลลัพธ์
Number of figures: 3
คำอธิบาย
gcf() = get current figure, คืนค่า Figure object ที่มี attribute .number