网络编程
位置:首页>> 网络编程>> Python编程>> jupyter notebook读取/导出文件/图片实例

jupyter notebook读取/导出文件/图片实例

作者:Doris_H_n_q  发布时间:2022-01-05 00:28:45 

标签: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')

jupyter notebook读取/导出文件/图片实例

导出文件

jupyter notebook读取/导出文件/图片实例

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

jupyter notebook读取/导出文件/图片实例

以上直接保存的方式打开图片呈现空白,解决方案:使用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 打印多个结果,否则只会打印最后一个结果过

来源:https://blog.csdn.net/Dorisi_H_n_q/article/details/82217025

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com