代码之家  ›  专栏  ›  技术社区  ›  Raven Cheuk

未显示海生散点图图例

  •  4
  • Raven Cheuk  · 技术社区  · 7 年前

    我试图用以下代码绘制一些数据

    from sklearn.datasets import make_blobs
    import seaborn as sns
    import numpy as np
    
    X, y = make_blobs(n_samples=1000, n_features=2, centers=10, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None)
    
    palette = np.array(sns.color_palette("bright", 10))  #Chossing color  
    sns.scatterplot(X[:,0],X[:,1],legend='full',c=palette[y])
    

    enter image description here

    颜色是美丽的,但传说是失踪的。

    如何绘制图例。如果简短,则为数字 hue size 变量 ....

    所以我似乎也需要包括 争论。 但是当我尝试 参数,则创建以下图形。。。

    sns.scatterplot(X[:,0],X[:,1],legend='full',hue=y,c=palette[y])
    

    enter image description here

    传说正在上演,但颜色不是我想要的。在添加 色调 参数,似乎覆盖了palete参数。不管我选什么颜色,颜色还是很难看。。。

    我的问题是:

    1 回复  |  直到 7 年前
        1
  •  3
  •   ImportanceOfBeingErnest    7 年前

    你需要使用 palette kwarg,并用你的 y

    from sklearn.datasets import make_blobs
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    X, y = make_blobs(n_samples=1000, n_features=2, centers=10, cluster_std=1.0,
                      center_box=(-10.0, 10.0), shuffle=True, random_state=None)
    
    palette = sns.color_palette("bright", 10)  #Choosing color
    sns.scatterplot(X[:, 0], X[:, 1], palette=palette, hue=y, legend='full')
    plt.show()
    

    enter image description here