Display only the lower half (upper half) with seaborn pair plot

Note that there was a way in https://tutorialmore.com/questions-1150768.htm.

import seaborn as sns
import matplotlib.pyplot as plt


def hide_current_axis(*args, **kwds):
    plt.gca().set_visible(False)

#Data frame preparation
X = sns.load_dataset("iris")

#Pair plot
pg = sns.pairplot(X)

#Erase the upper graph = display the lower triangular part
pg.map_upper(hide_current_axis)

#Erase the graph below = Display the upper triangle
# pg.map_lower(hide_current_axis)

#Erase the diagonal part
# pg.map_diag(hide_current_axis)
スクリーンショット 2020-02-26 22.45.00.png

Or place your favorite graph in any position with pairgrid.

from itertools import groupby
import seaborn as sns
import matplotlib.pyplot as plt


def hide_current_axis(*args, **kwds):
    plt.gca().set_visible(False)

    
def stackedhist(data, stackby, **kwds):
    groups = groupby(zip(stackby, data), lambda x: x[0])
    grouped_data = [[v for _, v in items] for key, items in groups]
    plt.hist(grouped_data, stacked=True, edgecolor='none')

    
#Data frame preparation
X = sns.load_dataset("iris")
    
g = sns.PairGrid(X, diag_sharey=False)
g.map_lower(sns.scatterplot, data=X, hue='species', alpha=0.3, edgecolor='none')
g.map_diag(stackedhist, stackby=X['species'])
g.map_upper(hide_current_axis)
スクリーンショット 2020-02-26 22.47.16.png

Recommended Posts

Display only the lower half (upper half) with seaborn pair plot
Enlarge the plot display.
Display only the resources created when acquiring AWS resources with Boto3
Plot the Nikkei Stock Average with pandas
Image display taken with the built-in ISIGHT
Display Python 3 in the browser with MAMP
Display markers above the border with matplotlib