python - 使用 Seaborn 删除一些 x 标签

标签 python seaborn

在下面的屏幕截图中,我所有的 x 标签都相互重叠。

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

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

enter image description here

最佳答案

我不确定为什么没有像 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()

结果:

enter image description here

关于python - 使用 Seaborn 删除一些 x 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38809061/

相关文章:

Python 解析文件中的行

python - 在 C 中嵌入 Python 以获取配置文件

python - 专门在 seaborn 集群图中更改热图的大小?

python - 根据颜色图着色的条形图?

python math.log 在较大的 int 下输出不准确?

python - 使用 Python 查找网络(外部)IP 地址

python - Pyspark DataFrame 中的嵌套 SELECT 查询

python - 如何使 Swarmplot (Seaborn) 中的点相互重叠?

python - 如何将权重传递给 Seaborn FacetGrid

python - 如何将数据从宽数据转换为长数据,以便根据时间绘制值