从 seaborn pairplot 中隐藏传奇 [英] Hide legend from seaborn pairplot

查看:29
本文介绍了从 seaborn pairplot 中隐藏传奇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏 Seaborn pairplot 图例.官方文档没有提到关键字图例.我使用 plt.legend 尝试的所有方法都不起作用.请建议最好的前进方式.谢谢!

I would like to hide the Seaborn pairplot legend. The official docs don't mention a keyword legend. Everything I tried using plt.legend didn't work. Please suggest the best way forward. Thanks!

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

test = pd.DataFrame({
    'id': ['1','2','1','2','2','6','7','7','6','6'],
    'x': [123,22,356,412,54,634,72,812,129,110],
    'y':[120,12,35,41,45,63,17,91,112,151]})
sns.pairplot(x_vars='x', y_vars="y", 
                 data=test,
                 hue = 'id', 
                 height = 3)

推荐答案

使用 pairplot 时需要返回 Seabron Pairgrid 对象,然后才能使用 访问 Pairgrid 的图例._legend.然后只需调用 remove():

You need to return the Seabron Pairgrid object when you use pairplot and then you can access the legend of the Pairgrid using ._legend. Then simply call remove():

import seaborn as sns

test = pd.DataFrame({
    'id': ['1','2','1','2','2','6','7','7','6','6'],
    'x': [123,22,356,412,54,634,72,812,129,110],
    'y':[120,12,35,41,45,63,17,91,112,151]})

g = sns.pairplot(x_vars='x', y_vars="y", data=test, hue = 'id', height = 3)
g._legend.remove()

这篇关于从 seaborn pairplot 中隐藏传奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆