不在有 DISPLAY 的情况下使用 matplotlib 是否可行?
我们可以在本地机器中保存当前数字并显示它。
步骤
- 设置图片大小并调整 subplot 之间以及周围的填充。
- 使用 numpy 创建 x 数据点。
- 使用 plot() 方法绘制 x 和 y 数据点。
- 使用 savefig() 方法保存图形。
示例
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-np.pi, np.pi, 100) plt.plot(x, np.sin(x) * x, c='red') plt.savefig("myimage.png")
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
输出
当执行代码时,它会将以下图像作为“myimage.png”保存在项目目录中。
广告