2012-09-08 70 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在特定位置明確地實例化軸。