如何在 Matplotlib 中让 pylab.savefig() 将图像保存为"最大化"窗口而非默认大小?
matplotlibserver side programmingprogramming更新于 2025/5/5 23:22:17
要将图像保存为最大化窗口而非默认大小,我们可以使用以下步骤 −
使用 figure() 方法创建图形,figsize=(7.50, 3.50)。
使用 plot() 方法绘制线条,其中 list、color=”red” 和 linewidth=2。
使用 savefig() 方法保存图形。
要显示图形,请使用 show() 方法。
示例
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
plt.plot([1, 3, 7, 3, 1], c="red", lw=2)
plt.savefig("full_image.png")
plt.show()
输出


