TensorFlow之Matplotlib(6)

Matplotlib  ——(分解)   Matrix   Plot   Library

                              矩阵 绘图  库

 

· 一个极其强大的Python绘图库。官网:matplotlib.org

· 很少的代码即可绘制2D/3D,静态/动态等各种图形

· 一般常用的是它的子包:PyPlot,提供类似MATLAB的绘图框架。

 

Matplotlib 的一般绘制流程:

准备数据 ——》 构建图像 ——》 显示图像

 

示例:vim Basic.py

 1 # -*- coding:utf-8 -*-
 2 
 3 #引入 Matplotlib 的分模块 PyPlot
 4 import matplotlib.pyplot as plt
 5 
 6 import numpy as np
 7 
 8 #创建数据
 9 x = np.linspace(-2, 2, 100)      #产生一个等差数列:-2为起始项,2为终止项,100为产生数目
10 #y = 3 * x + 4
11 y1 = 3 * x + 4
12 y2 = x ** 2
13 
14 
15 #创建图像
16 #plt.plot(x, y)
17 plt.plot(x, y1)
18 plt.plot(x, y2)
19 
20 
21 #显示图像
22 plt.show()

示例2:

 1 # -*- coding:utf-8 -*-
 2 
 3 #引入 Matplotlib 的分模块 PyPlot
 4 import matplotlib.pyplot as plt
 5 
 6 import numpy as np
 7 
 8 #创建数据
 9 x = np.linspace(-2, 2, 100)
10 y1 = 3 * x + 4
11 y2 = x ** 2
12 
13 
14 #构建第一张图
15 plt.figure(num=1, figsize=(7,6))
16 plt.plot(x, y1)
17 plt.plot(x, y2, color="red", linewidth=3.0, linestyle="--")
18 
19 #构建第二张图
20 plt.figure(num=2)
21 plt.plot(x, y2, color="green")
22 
23 #显示图像
24 plt.show()

 

posted on 2018-10-11 00:20  qiuqiu365  阅读(297)  评论(0编辑  收藏  举报