1,创建多个figure父对象
一个文件内绘制多个图像
plt.figure(num, figsize = (width, heigh))
num:图像编号
width,height:图像宽度,高度,
2,创建多个ax子对象
绘图区域:将一个fig大图分割为多个ax子图,分别绘制,同时输出
plt.subplot(nrows, ncols, plot_number)
nrows,横轴数量,类似表格的 行
ncols,纵轴数量,类似表格的 列
plot_number,当前绘制的ax子图位置,横轴x,纵轴y
3、fig、ax结合的简写
fig, ax = plt.subplots(
figsize=(12,3), # 父窗口大小
nrows=2, # 子图行数
ncols=3, # 子图列数
sharex=False, # 是否共享x轴
sharey=True, # 是否共享y轴
)
ax[0,0].plot([1,2,3])
ax[1,1].plot([1,3,2])
plt.show()
4、复杂绘图区域:pyplot子绘图区域
plt.subplot2grid(GridSpee,CurSpee,rowspan=1,colspan=1)
GridSpee:元组,这个图表共有几行几列
例如(3,3),表示将区域分隔成3行3列9块区域
CurSpee:当前选中第几行第几列的子图表
例如(1,0),这里表示第1行第0列(行列都以0开头)
rowspan:合并行
例如rowspan=2,合并本块和下方块
conlspan:合并列
例如colspan=3,合并本块和右侧两块
plt.figure(1, figsize=(17,10))
plt.subplot2grid(
(4,3),# 4行3列
(0,0),# 选中0行0列单元格
colspan=2, #合并3列
)
plt.plot([0,2,4,6,8], [1,5,3,9,7]) # X轴坐标值,Y轴坐标值
plt.subplot2grid((4,3),(1,0),rowspan=2,colspan=2) # 选中1行0列单元格,合并2行,合并2列
x = [1,3,5,7,9,11,13,15,17]
y = [2,-5,19,3,5,8,12,6,1]
plt.scatter(x, y)
plt.subplot2grid((4,3),(0,2),rowspan=3,colspan=1)
a = [15,5,9,22,4,-5,45,-22]
plt.boxplot(a)
plt.subplot2grid((4,3),(3,0),rowspan=1,colspan=1)
x = [1,2,3,4,5]
y = [3,6,1,8,2]
plt.bar(x, y)
plt.subplot2grid((4,3),(3,1),rowspan=1,colspan=1)
a = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
plt.imshow(a)
plt.subplot2grid((4,3),(3,2),rowspan=1,colspan=1)
p = [15,30,45,10]
plt.pie(p)