天天看点

python matplotlib figure的add_subplot方法

先定义画布

import matplotlib.pyplot as plt
f=plt.figure()
           

再定义副画布

此处add_subplot方法的参数是一个三位数

百位上的数代表画布上下分成几块

十位上的数代表画布左右分成几块

个位上的数代表该块副画布的编号

例如此处的代码就表示

该画布(f)上下以及左右均被分为1块

而副画布(f1)是第一块画布

又如

a=plt.figure()
a1=a.add_subplot(211)
a2=a.add_subplot(212)
           

该画布(a)上下被分为2块左右被分为1块

而副画布(a1)是第一块画布,a2是第二块画布

如图

python matplotlib figure的add_subplot方法