Plot lower triangle in a seaborn Pairgrid

后端 未结 2 407
死守一世寂寞
死守一世寂寞 2021-02-06 00:04

I\'m a bit struggling with seaborn Pairgrid.

Let\'s say I have a Pairgrid like this:

As you can see, the upper triangle plots mirror the lower triangle

2条回答
  •  攒了一身酷
    2021-02-06 00:40

    this is basically the same as the accepted answer, but uses the official methods from seaborn.PairGrid:

    import seaborn as sns
    import matplotlib.pyplot as plt
    sns.set(style="ticks")
    iris = sns.load_dataset("iris")
    
    def hide_current_axis(*args, **kwds):
        plt.gca().set_visible(False)
    
    g = sns.pairplot(iris)
    g.map_upper(hide_current_axis)
    

    hiding the lower half is also easy:

    g.map_lower(hide_current_axis)
    

    or hiding the diagonal:

    g.map_diag(hide_current_axis)
    

    alternatively, just use the PairGrid directly for more control:

    g = sns.PairGrid(iris, hue='species', diag_sharey=False)
    g.map_lower(sns.scatterplot, alpha=0.3, edgecolor='none')
    g.map_diag(sns.histplot, multiple="stack", element="step")
    g.map_upper(hide_current_axis)
    

    which gives:

提交回复
热议问题