参考了几篇博客,在这里做下总结:
add_subplot 需要创建实例fig,并且在fig实例的基础上添加子画布:
x = np.arange(5)
fig = plt.figure()
axes = fig.add_subplot(121)
axes.plot(x,x)
axes = fig.add_subplot(122)
axes.plot(x,-x)
而subplot无需创建实例,使用方法为:
x = np.arange(5)
plt.subplot(121)
plt.plot(x,x**2)
plt.subplot(122)
plt.plot(x,np.log(x+1))