Python 2.7 修改地物布局后,将suptitle置于居中位置

Python 2.7 修改地物布局后,将suptitle置于居中位置,python-2.7,matplotlib,figure,Python 2.7,Matplotlib,Figure,我有一个包含2x2子地块的图形。顶部和底部子图具有与我锚定到左侧图相同的图例,修改了我的全局地物布局,如下所示: 但我的标题不再居中!我在使用此命令进行所有修改后执行此操作: f.suptitle('Background Efficiency', fontsize=20) 有人知道如何使它居中吗?我尝试了tight_布局方法,但它修改了所有布局,并没有达到我想要的效果 用于绘制所有内容的函数: def customplot( plots ): i=0 titles=plots.

我有一个包含2x2子地块的图形。顶部和底部子图具有与我锚定到左侧图相同的图例,修改了我的全局地物布局,如下所示:

但我的标题不再居中!我在使用此命令进行所有修改后执行此操作:

f.suptitle('Background Efficiency', fontsize=20)
有人知道如何使它居中吗?我尝试了tight_布局方法,但它修改了所有布局,并没有达到我想要的效果

用于绘制所有内容的函数:

def customplot( plots ):
    i=0
    titles=plots.keys()
    figs={}
    # Create all the figures needed (1 per test efficiency)
    while i<len(plots):
            # Create the figure that will contain 4 subplots
            f, axarr = plt.subplots(2, 2)

            # Get the figures data to plot from the 'plots' dictionary
            mywindow=plots[titles[i]]

            # Get curves names (either 'k' or 'filtering') from the 'mywindow' dictionary
            curves_names=mywindow.keys()
            # Get xaxis varying parameter (either 'ratios' or 'dbsizes') from the 'mywindow' dictionary
            x_names=mywindow[curves_names[0]].keys()

            j=0
            while j<len(curves_names):
                    # Get the data to plot in a single subplot from the 'mywindow' dictionary
                    toplot=mywindow[curves_names[j]]
                    k=0
                    while k<len(x_names):
                            # Get the data of a single curve to plot from the 'toplot' dictionary
                            tosubplot=toplot[x_names[k]]

                            # The previous data is a dictionary containing int keys (curves to draw) and strings (xaxis or fixed parameters). We are saving them
                            ints=list()
                            strings=list()
                            ids=tosubplot.keys()
                            l=0
                            while l<len(ids):
                                    if isinstance( ids[l], ( int, long ) ):
                                            ints.append(ids[l])
                                            ints = sorted(set(ints))
                                    else:
                                            strings.append(ids[l])
                                    l+=1
                            # Tuning our subplot
                            if (k==0):
                                    lll='left'
                            else:
                                    lll='right'
                            axarr[j,k].set_title('Plotting ' + curves_names[j] + ' depending on ' + x_names[k], loc=lll)
                            axarr[j,k].grid('on')
                            xxx=tosubplot['x']
                            if(x_names[k]=='ratios'):
                                    minaxis=float(xxx[0]-(xxx[1]-xxx[0]))
                                    maxaxis=float(xxx[len(xxx)-1]+xxx[1]-xxx[0])
                                    axarr[j,k].axis([minaxis,maxaxis,0,1])
                            else:
                                    minaxis=int(xxx[0]-(xxx[1]-xxx[0]))
                                    maxaxis=int(xxx[len(xxx)-1]+xxx[1]-xxx[0])
                                    axarr[j,k].axis([minaxis,maxaxis,0,1])
                            if (k==0):
                                    axarr[j,k].set_ylabel('F-measure of the face recognition')
                            if (j==1 and k==0):
                                    axarr[j,k].set_xlabel('Ratio chosen to tune the recognition')
                            if (j==1 and k==1):
                                    axarr[j,k].set_xlabel('Size of the database')
                            l=0
                            # Plot all the curves in a subplot
                            while l<len(ints):
                                    # Create labels for the legend
                                    cstlabel=curves_names[j]
                                    if cstlabel=='k':
                                            cstlabel=cstlabel + ' = ' + str(ints[l])
                                    else:
                                            if ints[l]==0:
                                                    cstlabel='wavelets'
                                            elif ints[l]==1:
                                                    cstlabel='subsampling'
                                            elif ints[l]==2:
                                                    cstlabel='averaging'
                                    # Finally plotting
                                    axarr[j,k].plot(xxx[0:len(tosubplot[ints[l]])], tosubplot[ints[l]], 'o--', label=cstlabel)
                                    l+=1
                            k+=1
                    j+=1
            # Hiding xticks of top subplots and yticks of right subplots
            plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False)
            plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False)

            # Modify position of subplots to adjust the legends
            p=axarr[0,1].get_position()
            p=[p.x0+0.08, p.y0, p.width, p.height]
            axarr[0,1].set_position(p)
            p=axarr[1,1].get_position()
            p=[p.x0+0.08, p.y0, p.width, p.height]
            axarr[1,1].set_position(p)

            # Create the legends
            axarr[0,0].legend(bbox_to_anchor=(1.08,1), loc=2, ncol=1, borderaxespad=0.03, borderpad=1.5, labelspacing=1.5)
            axarr[1,0].legend(bbox_to_anchor=(1.05,1), loc=2, ncol=1, borderaxespad=0.00, borderpad=0.7, labelspacing=1.5)

            # Finally add the title
            f.suptitle(titles[i], fontsize=20)

            f.set_size_inches(18, 8, forward=True)
            # Saving the figure in the return list
            figs[titles[i]]=f
            i+=1
    return figs

你能发一封邮件吗?我的代码很大。。。我可以提供打印所有内容的函数,但您肯定可以将问题简化为更改子绘图布局和打印suptitle的代码?我添加了该函数。我有点喜欢python,所以我可能做错了。好吧,我知道你在做什么。也许你可以使用f.subplots\u adjustwspace=x在子地块之间创建空间,而不是手动将右侧的两个子地块向右移动0.08,其中x是你找到的某个数字,为你提供了正确的空间?