在下面的屏幕截图中,我所有的 x 标签都相互重叠。
g = sns.factorplot(x='Age', y='PassengerId', hue='Survived', col='Sex', kind='strip', data=train);
我知道我可以通过调用 g.set(xticks=[])
删除所有标签,但是有没有办法只显示一些年龄标签,比如 0、20、 40、60、80?
最佳答案
我不确定为什么没有像 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()
结果:
关于python - 使用 Seaborn 删除一些 x 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38809061/