在一個(gè)figure里創(chuàng)建多個(gè)小圖(Subplot)
方法參數(shù)subplot(nrows, ncols, index, **kwargs)
Returns
-------
axes : an.axes.SubplotBasesubclass of~.axes.Axes(or a subclass of~.axes.Axes)Examples
--------
plt.subplot(221)
# equivalent but more general
ax1=plt.subplot(2, 2, 1)
import matplotlib.pyplot as plt
plt.figure()
#兩行兩列第一個(gè)位置
plt.subplot(2,2,1)
plt.plot([0,1],[0,1])
'''
或者在子圖上畫
ax1 = plt.subplot(221)
ax1.plot([0,1],[0,1])
'''
plt.subplot(2,2,2)
plt.plot([0,1],[0,2])
plt.subplot(2,2,3)
plt.plot([0,1],[0,3])
plt.subplot(2,2,4)
plt.plot([0,1],[0,4])
plt.figure()
#兩行1列,第一個(gè)圖占一行
plt.subplot(2,1,1)
plt.plot([0,1],[0,1])
#第二行是兩行三列
plt.subplot(2,3,4)
plt.plot([0,1],[0,2])
plt.subplot(2,3,5)
plt.plot([0,1],[0,3])
plt.subplot(2,3,6)
plt.plot([0,1],[0,4])
plt.show()

第一個(gè)figure

第二個(gè)figure
2、plt.subplots():返回的是fig和ax對(duì)象
#創(chuàng)建畫布和子圖對(duì)象
fig, axes = plt.subplots(3,8#3行8列個(gè)圖
,figsize=(8,4)#figsize指的是圖的尺寸
,subplot_kw = {"xticks":[],"yticks":[]} #不要顯示坐標(biāo)軸
)
運(yùn)行結(jié)果

image.png