代码之家  ›  专栏  ›  技术社区  ›  aviss

把传说从海伯恩的配对中隐藏

  •  0
  • aviss  · 技术社区  · 6 年前

    plt.legend 没用。请提出最好的前进方向。谢谢!

    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)
    
    0 回复  |  直到 6 年前
        1
  •  21
  •   DavidG    6 年前

    使用时需要返回Seabron Pairgrid对象 pairplot 然后你可以使用 ._legend 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()
    

    enter image description here