首页 > 编程开发 > Python    日期:2020-05-26 / 来自互联网 / 浏览

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

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 打印多个结果,否则只会打印最后一个结果过

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

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章

1 2 3 4 5