matplotlib建立图的基本方法

1、基本术语

  1. figure 就是至关于画板的,画纸要铺在画板上
  2. Axes/subpot 指坐标系(轴域),至关于画纸,全部图都画在上面
  3. Axis 指坐标系(轴域)中的横竖轴

2、建立的方式说明

一、建立画纸的方式有两种:对象编程和函数编程。对于新手和复杂的图,仍是优先使用对象编程编程

import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
print type(fig)

# 里面传入的三个数字,前两个数字表明要生成几行几列的子图矩阵,底单个数字表明选中的子图位置, 调用add_subplot方法就会加一个图
# ax1 = fig.add_subplot(211)
# ax2 = fig.add_subplot(212)
# print type(ax1)
# ax1.plot([1, 2, 3], [1, 2, 3])

# 里面传入的两个数字表明要生成几行几列的子图矩阵,默认图已经建立好了,若是是单列或者单行返回的是一个一维数组,不然是二维数组
#ax = fig.subplots(1, 2)
# ax00 = ax[0, 0]
# ax01 = ax[0, 1]
# ax10 = ax[1, 0]
# ax11 = ax[1, 1]
#print ax.shape, type(ax)
# ax11.plot([1, 2, 3], [1, 2, 3])

# 括号里面的值前两个是轴域原点坐标(从左下角计算的),后两个是显示坐标轴的长度
# axe1 = fig.add_axes([0.1, 0.1, 0.8, 0.8])
# axe1.plot([1, 2, 3], [1, 2, 3])

plt.show()
相关文章
相关标签/搜索