控制Python seaborn packag中的tick标签

2024-10-02 22:30:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用seaborn包生成的散点图矩阵,我想删除所有的勾号标签,因为这些只是把图形弄乱了(要么是这个,要么只是删除x轴上的那些),但我不确定如何做,而且在谷歌搜索中没有成功。有什么建议吗?

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

enter image description here


Tags: import图形as矩阵area标签seaborn建议
2条回答
import seaborn as sns
iris = sns.load_dataset("iris")
g = sns.pairplot(iris)
g.set(xticklabels=[])

enter image description here

您可以使用列表理解循环遍历所有列并关闭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

您还可以将数据重新缩放为更可读的内容:

df /= 1e6
sns.pairplot(df)

enter image description here

相关问题 更多 >