如何使用python中jupyter存储图片
要在Jupyter Notebook中存储图片,可以使用以下步骤:
- 导入所需的库
import matplotlib.pyplot as plt
- 生成图像并显示
# 生成图像
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
# 显示图像
plt.show()
- 存储图像
# 存储图像
fig.savefig("my_plot.png")
在执行上述代码之后,会在当前工作目录下生成一个名为“my_plot.png”的图像文件。注意,如果要在Jupyter Notebook中显示图像,必须使用plt.show()函数,而在存储图像时则不需要。
原文地址: https://www.cveoy.top/t/topic/dhnf 著作权归作者所有。请勿转载和采集!