Python matplotlib中精确调整子图形大小

Python matplotlib中精确调整子图形大小,python,matplotlib,subplot,Python,Matplotlib,Subplot,我正在用A4纸绘制一些索引数据,其中6幅图像为3x2行。我已经准备好了基本代码,它将这个数据帧数据绘制成以下6个图 如何将子地块划分为A4/6大小相等的地块,并在顶部留出一点空间作为标题?与8.267/2 x 11.69/3尺寸相同?紧凑的布局有帮助,但我希望对尺寸和位置有更多的控制。如果需要更多的控制,可以使用fig.add\u轴 缺点是写/维护时会变得非常烦人,因为您必须确保记号和轴标签不会相互重叠 还有一种方法可以让您更好地控制跨列等等。在子批的上下文中,rect的值意味着什么?我可以看

我正在用A4纸绘制一些索引数据,其中6幅图像为3x2行。我已经准备好了基本代码,它将这个数据帧数据绘制成以下6个图


如何将子地块划分为A4/6大小相等的地块,并在顶部留出一点空间作为标题?与8.267/2 x 11.69/3尺寸相同?紧凑的布局有帮助,但我希望对尺寸和位置有更多的控制。

如果需要更多的控制,可以使用
fig.add\u轴

缺点是写/维护时会变得非常烦人,因为您必须确保记号和轴标签不会相互重叠


还有一种方法可以让您更好地控制跨列等等。

在子批的上下文中,rect的值意味着什么?我可以看到l、b、w、h部分,但左下角在这里是什么意思?
左下角
下角
是轴的左下角的位置,以数字分数为单位。我的回答解决了你的问题吗?
def plot_idx(df,image,key):
    # reset the default parameters
    plt.rcParams['font.size'] = 8.
    plt.rcParams['figure.figsize'] = (8.267, 11.692) #aA paper
    fig = plt.figure()
    #plot all the 6 figures and save the 3x2 image as png

    ax1 = fig.add_subplot(321) # first row first image
    #compute all time 
    alltime = df['Close'].count()
    x,y,x_min, y_min, x_max, y_max = min_max(df,alltime)
    ax1.plot(x, y,'r')
    ax1.plot(x_min,y_min,'o')
    ax1.plot(x_max,y_max,'o')
    ax1.set_xlabel('year')
    ax1.set_ylabel('Index Close')
    ax1.set_title(plot_title[-1])
    ax1.fill_between(x,y,facecolor='red')
    ax1.annotate(y_min, xy=(x_min,y_min), xytext=(x_min,y_min +250))
    ax1.annotate(y_max, xy=(x_max,y_max), xytext=(x_max,y_max +250))

    ax2 = fig.add_subplot(322) # first row second image
    # compute ytd 
    ytd = df.ix[baseline_year:]['Close'].count()
    x,y,x_min, y_min, x_max, y_max = min_max(df,ytd)
    ax2.plot(x, y,'r')
    ....
    # repeat 4 more times for other figs

    fig.suptitle(key, fontsize=10)
    plt.tight_layout()
    plt.savefig(image)
fig = plt.figure()
ax1 = fig.add_axes([.1, .1, .4, .4,])
ax2 = fig.add_axes([.1, .5, .4, .4,])
# ... and so one for as many figures as you want
# or wrap it all up in a loop