調整子圖布局,調用格式如下:
subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)
參數
有六個可選參數來控制子圖布局。值均為0~1之間。其中left、bottom、right、top圍成的區域就是子圖的區域。wspace、hspace分別表示子圖之間左右、上下的間距。實際的默認值由matplotlibrc文件控制的。
簡單示例
import matplotlib.pyplot as plt x=[1,2,3] y=[4,5,6] fig, axs = plt.subplots(2, 2) axs[0, 0].plot(x,y) axs[0, 1].plot(x,y) axs[1, 0].plot(x,y) axs[1, 1].plot(x,y) plt.subplots_adjust(left=0.1, bottom=0.5, right=0.8, wspace=0.01) plt.show()
運行結果如下: