I’ve been using Pandas .corr()
with Seaborn to generate a heatmap showing correlation, but want to switch to Pingouin’s .rcorr()
to give a bit more control.
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pingouin as pg
df_correlation = df.rcorr(method='spearman')
This gives a df similar to below (taken directly from the Pingouin documentation as an example).
Neuroticism Extraversion Openness Agreeableness
Neuroticism - *** **
Extraversion -0.35 - ***
Openness -0.01 0.265 - ***
Agreeableness -0.134 0.054 0.161 -
When using Pandas .corr()
I've been able to plot the heapmap directly using Seaborn, and then mask the upper diagonal, but this doesn't work due to the presence of ***
.
I'm looking for a way to plot this Pingouin-derived data as a heat map, by taking just the numbers (but a bonus if the *
can be included in the upper quadrant).
My current 'fix' for this is to use a series of .replace()
modifications to change '-' for '1' etc, but this does not seem like a great solution
df_correlation.replace(['-'], 1)
You could do something as follows:
Result:
SO sources: