plt.figure() − สร้างร่างใหม่หรือเปิดใช้งานตัวเลขที่มีอยู่
plt.subplots() − สร้างร่างและชุดของแผนย่อย
มาดูตัวอย่างเพื่อทำความเข้าใจความแตกต่างระหว่าง plt.subplots() และ plt.figure() .
ขั้นตอน
-
กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
-
สร้างร่างใหม่หรือเปิดใช้งานตัวเลขที่มีอยู่ ใช้ plt.figure() วิธีการ
-
สร้างร่างและชุดแผนย่อย ใช้ plt.subplots() วิธีการ
-
หากต้องการแสดงรูป ให้ใช้ แสดง() วิธีการ
ตัวอย่าง
from matplotlib import pyplot as plt
# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
# Create a new figure using plt.figure
fig1 = plt.figure("Figure 1 - plt.figure")
# Create a figure and set of subplots using plt.subplots
fig2, ax = plt.subplots()
plt.title("Figure 2 - plt.subplots")
# Display the plot
plt.show()
ผลลัพธ์
plt.figure() สร้างผลลัพธ์ต่อไปนี้

และ plt.subplots() สร้างผลลัพธ์ต่อไปนี้ -
