I created this heatmap to visualise the correlations between multiple columns of data in a period of time. I really like the heatmap, but I want to add the correleation coefficients as a number into each of the fields. Anyone know what I have to add in the code to do that?
def CorrMtx(ten_yr_bond_p4, dropDuplicates = True):
# Exclude duplicate correlations by masking uper right values
if dropDuplicates:
mask = np.zeros_like(corr_ten_yr_bond_p4, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Set background color / chart style
sns.set_style(style = 'white')
# Set up matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
# Add diverging colormap from red to blue
cmap = sns.diverging_palette(250, 10, as_cmap=True)
# Draw correlation plot with or without duplicates
if dropDuplicates:
sns.heatmap(corr_ten_yr_bond_p4, mask=mask, cmap=cmap,
square=True,
linewidth=.5, cbar_kws={"shrink": .5}, ax=ax)
else:
sns.heatmap(corr_ten_yr_bond_p4, cmap=cmap,
vmin=-1, vmax=1, center=0,
square=True,
linewidth=.5, cbar_kws={"shrink": .5}, ax=ax)
CorrMtx(corr_ten_yr_bond_p4, dropDuplicates = False)
