2012-09-08 42 views
1

我需要格式化一些帮助。如何更改第二和第三图形之间的距离Matplotlib图形放置

from matplotlib.font_manager import FontProperties 
    import matplotlib.pyplot as plt 


    fig = plt.figure(1) 
    graph1 = fig.add_subplot(3,1,1) 
    graph2 = fig.add_subplot(3,1,2) 
    norm = fig.add_subplot(3,1,3) 

    graph1.set_title(TITLE + '\nscaling factor: ' +str(round(rescale,3))) 
    norm.set_title('Circle and Oval Height Difference') 
    norm.set_xlabel(XLABEL +'(Degrees)') 
    norm.legend(bbox_to_anchor=(1.13,1), prop={'size':8}) 
    plt.ylabel('Heights (nm)') 


    graph1.legend(bbox_to_anchor=(1.13,1),prop={'size':8}) 
    graph2.legend(bbox_to_anchor=(1.13,1),prop={'size':8}) 
    fontP = FontProperties() 
    fontP.set_size('small') 

enter image description here

+2

x轴是否意味着相同? (如果是这样,你可以通过明确地共享它们来节省很多空间,只显示底部的x轴。) –

+0

是的,它们是相同的,所以我该如何改变它 – user1462442

回答

2

使用

plt.subplots_adjust(hspace=desiredspace) 

我敢肯定,matplotlib的方式是,可能会有一些更多的方法那样做,但它解决了我的问题,甚至不得不亲自找出最佳价值。

希望这会有所帮助!

4

快速回答是fig.subplots_adjust,将hspace设置为更大的值。不幸的是,这也在顶部两个图之间插入了一些空间,但这可能是好的,取决于你想要什么。正如乔所说,如果他们是相同的,我经常删除X轴。

如果你想要有不均匀的间距,即2和3之间的间隔比1和2之间的间距要大,你需要使用fig.add_axes在特定位置明确地实例化轴。