考虑不调用 subplots 并使用 height 和 aspect 参数,因为这个 seaborn factorplot solution 显示aspect 是高度的宽度倍数,可能保持尺寸一致:
sns.catplot(x='xdata', y='ydata', data=df, kind='swarm', height=5, aspect=2)
来自help(sns.catplot) 输出:
height : scalar, optional
Height (in inches) of each facet. See also: ``aspect``.
aspect : scalar, optional
Aspect ratio of each facet, so that ``aspect * height`` gives the width
of each facet in inches.
用随机数据演示:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
np.random.sample(71318)
df = pd.DataFrame({'xdata': np.random.choice(['pandas', 'r', 'julia', 'sas', 'spss', 'stata'], 100),
'ydata': np.random.choice(range(1,6), 100)})
sns.catplot(x='xdata', y='ydata', data=df, kind='swarm', height=5, aspect=2)
plt.show()
plt.clf()
plt.close()