zxy0307's picture
Upload 141 files
593040d verified
raw
history blame contribute delete
792 Bytes
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()