matplotlib绘制多个子图

import numpy as np
import matplotlib.pyplot as plt

# 在Matplotlib中,Figure(图像)对象是整个绘图区域,
# 可以包含一个或者多个axes,其中每个axes拥有自己的坐标系,是一个单独的绘图区域,
# axes 可以在整个绘图区域任意摆放。用户可以通过subplot来绘制多个子图,
# 通过subplot()创建的子图只能按网格整齐排列
plt.figure()
# 绘制一个子图,其中row=2,co1=2,该子图占第1个位置
plt.subplot(2, 2, 1)
plt.plot([0, 1], [0, 1])
# 绘制一个子图,其中row=2,col=2,该子图占第2个位置
plt.subplot(2, 2, 2)
plt.plot([0, 1], [1, 0])

plt.subplot(2, 2, 3)
plt.plot([1,2], [2, 1])

plt.subplot(2, 2, 4)
plt.plot([1, 2], [1, 2])
plt.show()

你可能感兴趣的:(python,python,matplotlib)