Matplotlib:您可以使用子图更改行的相对高度吗
Matplotlib: can you change the relative height of rows using subplots
我有一个看起来像这样的多面板图
代码:
f = plt.figure(figsize=(8, 6))
plt.subplot(211)
plt.subplot(245)
plt.subplot(246)
plt.subplot(247)
plt.subplot(248)
我想保留这个布局,但是让顶行在图中占据更大的比例。我将如何使顶部丝束占据图形高度的 2/3 而底部行占据图形高度的 1/3?
有几种方法可以解决,其中大部分在 Customizing Figure Layouts Using GridSpec and Other Functions
中有详细说明
这里是使用GridSpec
的演示
gs0 = matplotlib.gridspec.GridSpec(2,4, height_ratios=[2,1])
fig = plt.figure()
ax = fig.add_subplot(gs0[0,:])
ax = fig.add_subplot(gs0[1,0])
ax = fig.add_subplot(gs0[1,1])
ax = fig.add_subplot(gs0[1,2])
ax = fig.add_subplot(gs0[1,3])
我有一个看起来像这样的多面板图
代码:
f = plt.figure(figsize=(8, 6))
plt.subplot(211)
plt.subplot(245)
plt.subplot(246)
plt.subplot(247)
plt.subplot(248)
我想保留这个布局,但是让顶行在图中占据更大的比例。我将如何使顶部丝束占据图形高度的 2/3 而底部行占据图形高度的 1/3?
有几种方法可以解决,其中大部分在 Customizing Figure Layouts Using GridSpec and Other Functions
中有详细说明这里是使用GridSpec
gs0 = matplotlib.gridspec.GridSpec(2,4, height_ratios=[2,1])
fig = plt.figure()
ax = fig.add_subplot(gs0[0,:])
ax = fig.add_subplot(gs0[1,0])
ax = fig.add_subplot(gs0[1,1])
ax = fig.add_subplot(gs0[1,2])
ax = fig.add_subplot(gs0[1,3])