要调整多图布局的 matplotlib/seaborn 子图之间的空间,我们可以采取以下步骤
设置图形大小并调整子图之间和周围的填充。
创建一个图形和一组子图。
调整子图布局参数。
为所有子图创建 Seaborn 箱线图。
要显示图形,请使用Show()方法。
import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axes = plt.subplots(2, 2) # Adjust the subplot layout parameters fig.subplots_adjust(hspace=0.125, wspace=0.125) # Create Seaborn boxplot for all the subplots sns.boxplot(ax=axes[0, 0]) sns.boxplot(ax=axes[0, 1]) sns.boxplot(ax=axes[1, 0]) sns.boxplot(ax=axes[1, 1]) # Display the plot plt.show()输出结果
它将产生以下输出 -