用Seaborn删除一些x标签

Hue*_*uey 10 python seaborn

在下面的屏幕截图中,我的所有x标签彼此重叠.

g = sns.factorplot(x='Age', y='PassengerId', hue='Survived', col='Sex', kind='strip', data=train);
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过调用删除所有标签g.set(xticks=[]),但有没有办法只显示一些Age标签,如0,20,40,60,80?

在此输入图像描述

ber*_*nie 17

我不确定为什么没有合理的默认刻度和y轴上的值.无论如何,您可以执行以下操作:

import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

titanic = sns.load_dataset('titanic')
sns.factorplot(x='age',y='fare',hue='survived',col='sex',data=titanic,kind='strip')
ax = plt.gca()
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%d'))
ax.xaxis.set_major_locator(ticker.MultipleLocator(base=20))
plt.show()
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述