簡體   English   中英

我無法改變matplotlib中子圖之間的距離

[英]I am not able to change the distance between to subplots in matplotlib

我是python的新手,我正在將兩個imshow對象繪制成一個圖形,一個在另一個之下。 但是,我無法改變兩個物體之間的水平距離,即它們相距太遠。

正如使用matplotlib中的許多子圖改進子圖大小/間距所建議的那樣,我嘗試使用plt.tight_layout()plt.subplots_adjust ,但它根本不影響繪圖。

這就是我創建繪圖的方式(我省略了我定義要繪制的數組的部分以及imshow繪圖的屬性):

fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.imshow(help_vector, cmap=cmap, norm=norm)
ax2 = fig.add_subplot(212)
ax2.imshow(plot_vector, cmap=cmap, norm=norm)

我不知道這是否重要,但兩個子圖都有一個標題,整個圖有一個標題,第二個子圖有一個“圖例”,它是我用下面的代碼創建的:

patches = [mpatches.Patch(color='lime', label = 'No relevant error'), mpatches.Patch(color='yellow',label='Medium error'), mpatches.Patch(color='orange',label='Large error'), mpatches.Patch(color='red',
    label='Unacceptable')]
    plt.legend(handles=patches, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0)

使用savefig存儲圖像時,我添加了參數bbox_inches='tight'

情節的圖像

非常感謝任何形式的幫助!

編輯:添加了圖表的圖像。

正如@ImportanceOfBeingErnest指出的那樣,解決方案是使用subplots_adjust subplots_adjust()topbottom參數。 就我而言, fig.subplots_adjust(top=0.7,bottom=0.3)是我所需要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM