Seaborn

Seaborn怎么调整子图间距

小亿
93
2024-05-17 19:52:25
栏目: 编程语言

要调整Seaborn子图之间的间距,可以使用plt.subplots_adjust()方法来控制子图之间的间距。该方法接受参数left, bottom, right, top, wspace, hspace,分别表示子图距离画布左、下、右、上的距离以及子图之间的水平和垂直间距。

下面是一个示例代码,演示了如何调整Seaborn子图之间的间距:

import seaborn as sns
import matplotlib.pyplot as plt

# 创建一个包含多个子图的图形
fig, axs = plt.subplots(2, 2, figsize=(10, 10))

# 调整子图之间的间距
plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9, wspace=0.4, hspace=0.4)

# 在子图中绘制Seaborn图形
sns.scatterplot(x='sepal_length', y='sepal_width', data=iris, ax=axs[0, 0])
sns.boxplot(x='species', y='petal_length', data=iris, ax=axs[0, 1])
sns.barplot(x='species', y='petal_width', data=iris, ax=axs[1, 0])
sns.histplot(iris['sepal_length'], kde=True, ax=axs[1, 1])

plt.show()

在这个示例中,plt.subplots_adjust()方法被用来调整子图之间的间距,通过调整wspacehspace参数来控制子图之间的水平和垂直间距。您可以根据需要调整这些参数的值来达到您想要的子图间距效果。

0
看了该问题的人还看了