Matplotlib - plt.subplots() 和 plt.figure() 之間
plt.figure() - 建立一個新圖形或啟用一個現有的圖形。
plt.subplots() - 建立一個圖形和一組子圖。
我們舉一個例子來了解 plt.subplots() 和 plt.figure() 之間的區別。
步驟
設定圖形大小並調整子圖之間和周圍的間距。
建立一個新圖形或啟用一個現有的圖形。使用 plt.figure() 方法。
建立一個圖形和一組子圖。使用 plt.subplots() 方法。
要顯示圖形,請使用 Show() 方法。
例項
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() 產生以下輸出 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP