image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

data = pd.read_csv('../input/world-happiness/2019.csv')

correlation_matrix_data = data.corr()

# Correlation Matrix function in Matplotlib 👩‍🚒
fig, ax= plt.subplots(figsize=(6,6))
cp=ax.matshow(correlation_matrix_data)
ax.set_title('Correlation Matrix Plot')
# Annotate the values into correlation plot
for (i, j), z in np.ndenumerate(correlation_matrix_data):
    ax.text(j, i, '{:0.2f}'.format(z), ha='center', va='center')
fig.colorbar(cp, ax=ax,fraction=0.046, pad=0.04);

# fraction=0.046, pad=0.04 seem like a magical combination to keep the colorbar scaled to the plot all the time 🙄

-Seaborn
-sns.heatmap(df.corr())

fig, ax = plt.subplots(figsize=(8, 8))
cmap = plt.get_cmap('magma', 30)
ax = sns.heatmap(correlation_matrix_data, annot=True, fmt='0.3f', square=True, cmap=cmap, cbar_kws={'shrink': 0.8})
ax.set_title('Correlation Matrix Plot', fontsize=13)