File size: 792 Bytes
593040d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import random

import matplotlib.pyplot as plt

"""
subplots函数:
    plt.subplots(nrows, ncols) -- 无法合并单元格,不灵活
"""
figure, axis = plt.subplots(2, 2)  # 将画布分成 2行2列 -- 返回画布和轴

# 绘制子图 -- 第一个绘图区域绘制 折线图
axis[0, 0].plot([1, 2, 3, 4, 5], [random.randint(1, 10) for i in range(5)])

# 绘制子图 -- 第二个绘图区域绘制 散点图
axis[0, 1].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)]

axis[1, 0].bar(x, y)

# 绘制子图 -- 第四个绘图区域绘制 饼图
x = [random.randint(10, 50) for i in range(5)]

axis[1, 1].pie(x, autopct='%1.1f%%')
plt.show()