Why are no colors shown in kde subplots in seaborn pairplot?

前端 未结 1 812
野性不改
野性不改 2020-12-21 08:25

I am looking at the iris data set (Fisher 1936). e.g. https://www.kaggle.com/uciml/iris/downloads/Iris.csv

Creating the seaborn pairplot with the arguments



        
相关标签:
1条回答
  • 2020-12-21 09:08

    There was an the issue with producing hues on the diagonal of sns.pairplot. This issue is now fixed in version 0.8.1 of seaborn.

    In case one is still interested, the following may be a workaround. You may create the underlying PairGrid yourself and map the diagonal and the off_diagonal elements individually. For the diagonal elements, get a color from the current cycler first, then use this color for the kdeplot.

    import matplotlib.pyplot as plt
    import seaborn as sns
    iris = sns.load_dataset("iris")
    
    g =  sns.PairGrid(iris, hue='species', size=2)
    
    def f(x, **kwargs):
        kwargs.pop("color")
        col = next(plt.gca()._get_lines.prop_cycler)['color']
        sns.kdeplot(x, color=col, **kwargs)
    
    g.map_diag(f)
    g.map_offdiag(plt.scatter)
    g.add_legend()
    plt.show()
    

    0 讨论(0)
提交回复
热议问题