Is it possible to remove the empty side of the scatter plot matrix?

Question:

I would like to remove the 6 empty boxes on the top right side of the plot(pls see the figure marked in red). I tried few different arguments and it didn’t work.
Here is the code I used.

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Example dataset
iris = sns.load_dataset("iris")

# Create PairGrid object with subplots
g = sns.PairGrid(iris, height=1.5, aspect=1.2)

# Create scatter plots on the lower side
g.map_lower(sns.scatterplot)

# Add regression line
g.map_lower(sns.regplot)

# Add histograms
g.map_diag(sns.histplot, kde=True)

# Then include correlation values for each scatter plot.
for i, j in zip(*plt.np.triu_indices_from(g.axes, k=1)):
    corr_coef = plt.np.corrcoef(iris.iloc[:, i], iris.iloc[:, j])[0][1]
    g.axes[j, i].annotate(f"R = {corr_coef:.2f}", xy=(.1, .9), xycoords=g.axes[j, i].transAxes)
    
plt.show()

enter image description here

Asked By: user115916

||

Answers:

You can use corner argument like this:

g = sns.PairGrid(iris, height=1.5, aspect=1.2, corner=True)

Result:
enter image description here

Answered By: maciek97x
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.