I had this problem that I wanted to somehow highlight statistically not significant correlations in seaborn
's heatmap. I knew I could hide them with the following code:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import pearsonr
planets = sns.load_dataset('planets')
# get the p value for pearson coefficient, subtract 1 on the diagonal
pvals = planets.corr(method=lambda x, y: pearsonr(x, y)[1]) - np.eye(*planets.corr().shape)
# set the significance threshold
psig = 0.05
plt.figure(figsize=(6,6))
sns.heatmap(planets.corr()[pvals<psig], annot=True, square=True)
However, that creates these weird white holes and I would like to keep the values and the information, I would just like to emphasise it with another colour.