我需要把两个小情节加到一个数字上.一个小地块需要大约是第二个小地块的三倍宽(高度相同).我使用GridSpec
和colspan
参数实现了这一点,但是我想使用figure
来完成,这样我就可以保存为PDF.我可以使用构造函数中的figsize
参数调整第一个图形,但是如何更改第二个绘图的大小呢?
我需要把两个小情节加到一个数字上.一个小地块需要大约是第二个小地块的三倍宽(高度相同).我使用GridSpec
和colspan
参数实现了这一点,但是我想使用figure
来完成,这样我就可以保存为PDF.我可以使用构造函数中的figsize
参数调整第一个图形,但是如何更改第二个绘图的大小呢?
subplots
function and pass the width ratio with gridspec_kw
import numpy as np
import matplotlib.pyplot as plt
# generate some data
x = np.arange(0, 10, 0.2)
y = np.sin(x)
# plot it
f, (a0, a1) = plt.subplots(1, 2, gridspec_kw={'width_ratios': [3, 1]})
a0.plot(x, y)
a1.plot(y, x)
f.tight_layout()
f.savefig('grid_figure.pdf')
# plot it
f, (a0, a1, a2) = plt.subplots(3, 1, gridspec_kw={'height_ratios': [1, 1, 3]})
a0.plot(x, y)
a1.plot(x, y)
a2.plot(x, y)
f.tight_layout()