参考:
https://docs.scipy.org/doc/numpy-dev/user/quickstart.html
http://matplotlib.org/gallery/index.html
http://matplotlib.org/tutorials/introductory/images.html
import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg # 基本的矩阵操作 # *与dot的不同 """ A = np.random.randint(1,10,(2,2)) print(A) print(A-A) print(A*A) print(A.dot(A)) """ # 矩阵对列和行求和 """ A = np.random.randint(1,10,(2,2)) print(A) print(A.sum(axis=0)) # 对列求和 print(A.sum(axis=1)) # 对行求和 """ # 生成一定范围的数据 """ data = np.arange( 0, 2, 0.3 ) plt.plot(data, 'ro') plt.show() """ # 生成等间隔的一定数量的数据 """ from numpy import pi x = np.linspace( 0, 2*pi, 100 ) y = np.sin(x) plt.plot(x, y) plt.show() """ # 生成随机数据 """ data = np.random.rand(10) # [0,1)之间的均匀分布 # data = np.random.randn(10) # 标准正态分布 plt.plot(data) plt.show() """ # 折线图 """ plt.plot([1,2.5,3,4]) plt.ylabel('some numbers') plt.show() """ # 散点图 """ plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) # 设置x轴和y轴的范围 plt.show() """ # 大量数据 """ # evenly sampled time at 200ms intervals t = np.arange(0., 5., 0.2) # red dashes, blue squares and green triangles plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.show() """ # 多个子图 """ def f(t): return np.exp(-t) * np.cos(2*np.pi*t) t1 = np.arange(0.0, 5.0, 0.1) t2 = np.arange(0.0, 5.0, 0.02) plt.figure(1) plt.subplot(211) # 2行1列第1个图 plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') plt.subplot(212) # 2行1列第2个图 plt.plot(t2, np.cos(2*np.pi*t2), 'r--') plt.show() """ # 显示图片 """ img = mpimg.imread('stinkbug.png') print(img.shape) # 375*500*3 plt.imshow(img) plt.show() """ # 保存图片 """ mpimg.imsave('out.png',img) """