在 Python seaborn 包中控制刻度标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32542957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:45:59  来源:igfitidea点击:

Control tick labels in Python seaborn package

pythonpandasipythonseaborn

提问by dsaxton

I have a scatter plot matrix generated using the seabornpackage and I'd like to remove all the tick mark labels as these are just messying up the graph (either that or just remove those on the x-axis), but I'm not sure how to do it and have had no success doing Google searches. Any suggestions?

我有一个使用该seaborn包生成的散点图矩阵,我想删除所有刻度线标签,因为它们只是弄乱了图形(或者只是删除了 x 轴上的那些),但我不确定如何做到这一点并且在谷歌搜索中没有成功。有什么建议?

import seaborn as sns
sns.pairplot(wheat[['area_planted',
    'area_harvested',
    'production',
    'yield']])
plt.show()

enter image description here

在此处输入图片说明

采纳答案by mwaskom

import seaborn as sns
iris = sns.load_dataset("iris")
g = sns.pairplot(iris)
g.set(xticklabels=[])

enter image description here

在此处输入图片说明

回答by Alexander

You can use a list comprehension to loop through all columns and turn off visibility of the xaxis.

您可以使用列表理解来遍历所有列并关闭 xaxis 的可见性。

df = pd.DataFrame(np.random.randn(1000, 2)) * 1e6
sns.pairplot(df)

enter image description here

在此处输入图片说明

plot = sns.pairplot(df)
[plot.axes[len(df.columns) - 1][col].xaxis.set_visible(False) 
 for col in range(len(df.columns))]
plt.show()

enter image description here

在此处输入图片说明

You could also rescale your data to something more readable:

您还可以将数据重新调整为更具可读性的内容:

df /= 1e6
sns.pairplot(df)

enter image description here

在此处输入图片说明