Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Figure模塊提供了頂層Artist,即Figure,其中包含所有繪圖元素。此模塊用於控製所有圖元的子圖和頂層容器的默認間距。
matplotlib.figure.Figure.savefig()方法
matplotlib庫的savefig()方法圖形模塊用於保存當前圖形。
用法:savefig(self, fname, *, transparent=None, **kwargs)
參數:此方法接受下麵討論的以下參數:
- fname:此參數是文件名字符串。
返回值:此方法不返回任何值。
以下示例說明了matplotlib.figure中的matplotlib.figure.Figure.savefig()函數:
範例1:
# Implementation of matplotlib function
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
s = ax.scatter([1, 2, 3], [4, 5, 6])
s.set_url('http://www.google.com')
fig.savefig('scatter.svg')
fig.suptitle("""matplotlib.figure.Figure.savefig()
function Example\n\n""", fontweight ="bold")
plt.show()
輸出:
範例2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
im = ax.imshow(Z,
interpolation ='bilinear',
cmap = cm.gray,
origin ='lower',
extent =[-3, 3, -3, 3])
fig.savefig('image.svg')
fig.suptitle("""matplotlib.figure.Figure.savefig()
function Example\n\n""", fontweight ="bold")
plt.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.figure.Figure.savefig() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。