#方法1:用matplotlib.gridspec.GridSpec自定义网格大小,然后添加子图fig.add_subplot
import matplotlib.pyplot as plt
import matplotlib.gridspec
x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)
gs = matplotlib.gridspec.GridSpec(3,2, width_ratios=[1,1.4],
height_ratios=[1,3,1])
fig = plt.figure()
ax1 = fig.add_subplot(gs[:,0])
# ax1.plot([1,3,2,4])
ax1.plot(x1, y1, '-og', ms=3)
ax2 = fig.add_subplot(gs[1,1])
# ax2.plot([1,3,2,4])
ax2.plot(x2, y2, '-ob', ms=3)
plt.show()
#方法二:利用fig.add_axes添加子图,同时指定子图axes的大小(传入比例大小参数)
import numpy as np
import matplotlib.pyplot as plt
fig = plt.fi