1、直接在编辑器中查看文件内容
读取文件内容到data变量中:
data = np.loadtxt('data/populations.txt')
year, hares, lynxes, carrots = data.T # trick: columns to variables
再进行绘制:
from matplotlib import pyplot as plt
plt.axes([0.2, 0.1, 0.5, 0.8])
plt.plot(year, hares, year, lynxes, year, carrots)
plt.legend(('Hare', 'Lynx', 'Carrot'), loc=(1.05, 0.5))
输出:
<matplotlib.legend.Legend at 0x10f8bc710>
再进行一些计算,相应的计算可参考前一篇文章
2、读取图片
from IPython.display import Image
Image(filename='images/numpy_image.png')
输出即为一张图片