import random | |
import matplotlib.pyplot as plt | |
""" | |
add_subplot函数 | |
fig.add_subplot(行,列,区域) | |
""" | |
fig = plt.figure() # 绘制画布 | |
# 绘制第一个子图 | |
ax1 = fig.add_subplot(2, 2, 1) | |
ax1.plot([1, 2, 3, 4, 5], [random.randint(1, 10) for i in range(5)]) | |
# 绘制第二个子图 | |
ax2 = fig.add_subplot(2, 2, 2) | |
ax2.plot([1, 2, 3, 4, 5], [random.randint(1, 10) for i in range(5)], 'ro') | |
# 绘制第三个子图 | |
x = [1, 2, 3, 4, 5] | |
y = [random.randint(10, 50) for i in range(5)] | |
ax3 = fig.add_subplot(2, 1, 2) | |
ax3.bar(x, y) | |
plt.show() | |