如何使用Jupyter Notebook读取、导出文件或图片实例?

2026-05-27 02:131阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计360个文字,预计阅读时间需要2分钟。

如何使用Jupyter Notebook读取、导出文件或图片实例?

我尽量简化并改写以下内容,不超过100字:

少说多做,看代码!pythonimport numpy as npimport matplotlib.pyplot as pltimport pandas as pdfrom pandas import Series, DataFrame

如何使用Jupyter Notebook读取、导出文件或图片实例?

我就废话不多说,看代码!

import numpy as np import matplotlib.pyplot as plt import pandas as pd from pandas import Series,DataFrame # 如果不添加该行,则每次显示图片都需要加上plt.show %matplotlib inline

读入文件:pd.read_csv('./test.csv')

读入图片:plt.imread('./d.jpg')

导出文件

保存图片 plt.savefig('./66.png')

以上直接保存的方式打开图片呈现空白,解决方案:使用fig=plt.gcf()保存当前图片

s=np.random.randint(0,255,(300,400,3),dtype = np.uint8) '''画图的时候获取当前图像(这一点非常类似于 Matlab 的句柄的概念)''' # gcf: Get Current Figure fig=plt.gcf() plt.imshow(s) fig.savefig('./666.jpg') fig.savefig('./666.png')

补充知识:Jupyter notebook如何打印多个结果

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity='all'

输入上面代码,才能让Jupyter notebook 打印多个结果,否则只会打印最后一个结果过

以上这篇jupyter notebook读取/导出文件/图片实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计360个文字,预计阅读时间需要2分钟。

如何使用Jupyter Notebook读取、导出文件或图片实例?

我尽量简化并改写以下内容,不超过100字:

少说多做,看代码!pythonimport numpy as npimport matplotlib.pyplot as pltimport pandas as pdfrom pandas import Series, DataFrame

如何使用Jupyter Notebook读取、导出文件或图片实例?

我就废话不多说,看代码!

import numpy as np import matplotlib.pyplot as plt import pandas as pd from pandas import Series,DataFrame # 如果不添加该行,则每次显示图片都需要加上plt.show %matplotlib inline

读入文件:pd.read_csv('./test.csv')

读入图片:plt.imread('./d.jpg')

导出文件

保存图片 plt.savefig('./66.png')

以上直接保存的方式打开图片呈现空白,解决方案:使用fig=plt.gcf()保存当前图片

s=np.random.randint(0,255,(300,400,3),dtype = np.uint8) '''画图的时候获取当前图像(这一点非常类似于 Matlab 的句柄的概念)''' # gcf: Get Current Figure fig=plt.gcf() plt.imshow(s) fig.savefig('./666.jpg') fig.savefig('./666.png')

补充知识:Jupyter notebook如何打印多个结果

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity='all'

输入上面代码,才能让Jupyter notebook 打印多个结果,否则只会打印最后一个结果过

以上这篇jupyter notebook读取/导出文件/图片实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。