使用 Matplotlib 從 iPython 筆記本儲存 figure 為檔案
要從 iPython 將圖形儲存為檔案,我們可以執行以下步驟 -
- 建立新的圖形或啟用現有的圖形。
- 使用 add_axes() 方法將座標系新增到圖形。
- 繪製給定的列表。
- 使用 savefig() 方法儲存繪圖。
示例
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_axes([1, 1, 1, 1])
plt.plot([1, 2])
plt.savefig('test.png', bbox_inches='tight')輸出
當我們執行程式碼時,它會將以下繪圖儲存為 "test.png"。

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