1、fig,ax = plt.subplots()
fig,ax = plt.subplots()等价于:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
fig, ax = plt.subplots(1,3),其中参数1和3分别代表子图的行数和列数,一共有 1x3 个子图像。函数返回一个figure图像和子图ax的array列表。
fig, ax = plt.subplots(1,3,1),最后一个参数1代表第一个子图。
如果想要设置子图的宽度和高度可以在函数内加入figsize值
fig, ax = plt.subplots(1,3,figsize=(15,7)),这样就会有1行3个15x7大小的子图。
subplots函数定义如下:
def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
subplot_kw=None, gridspec_kw=None, **fig_kw)
参数
nrows,ncols:
- 子图的行列数。
sharex, sharey:
- 设置为 True 或者 ‘all’ 时,所有子图共享 x 轴或者 y 轴,
- 设置为 False or ‘none’ 时,所有子图的 x,y 轴均为独立,
- 设置为 ‘