<jupyter_start><jupyter_text>______Copyright by <NAME> Inc.For more information, visit us at www.pieriandata.com   Matrix Plots**NOTE: Make sure to watch the video lecture, not all datasets are well suited for a heatmap or clustermap.**  Imports<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>The DataWorld Population Prospects publishes United Nations population estimates for all world countries and every year from 1950 to 2020, as well as projections for different scenarios (low, middle and high variants) from 2020 to 2100. The figures presented here correspond to middle variant projections for the given year.https://www.ined.fr/en/everything_about_population/data/all-countries/?lst_continent=900&lst_pays=926Source : Estimates for the current year based on data from the World Population Prospects. United Nations.<jupyter_code># 2020 Projections
df = pd.read_csv('country_table.csv')
df<jupyter_output><empty_output><jupyter_text>Heatmap<jupyter_code>df = df.set_index('Countries')
df
# Clearly shows life expectancy in different units
sns.heatmap(df)
rates = df.drop('Life expectancy',axis=1)
sns.heatmap(rates)
sns.heatmap(rates,linewidth=0.5)
sns.heatmap(rates,linewidth=0.5,annot=True)
# Note how its not palette here
sns.heatmap(rates,linewidth=0.5,annot=True,cmap='viridis')
# Set colorbar based on value from dataset
sns.heatmap(rates,linewidth=0.5,annot=True,cmap='viridis',center=40)
# Set colorbar based on value from dataset
sns.heatmap(rates,linewidth=0.5,annot=True,cmap='viridis',center=1)<jupyter_output><empty_output><jupyter_text>ClustermapPlot a matrix dataset as a hierarchically-clustered heatmap.<jupyter_code>sns.clustermap(rates)
sns.clustermap(rates,col_cluster=False)
sns.clustermap(rates,col_cluster=False,figsize=(12,8),cbar_pos=(-0.1, .2, .03, .4))
rates.index.set_names('',inplace=True)
rates
# Recall you can always edit the DF before seaborn
sns.clustermap(rates,col_cluster=False,figsize=(12,8),cbar_pos=(-0.1, .2, .03, .4))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10528823249166269, 'fraction_numerical': 0.027632205812291567, 'mean_word_length': 7.571428571428571, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '517990', 'license': 'MIT', 'n_tokens_mistral': 773, 'n_tokens_neox': 698, 'n_words': 180, 'path': 'Data Science Resources/Jose portila - ML/05-Seaborn/06-Matrix-Plots.ipynb', 'repo_name': 'FarzinRad/CS-Tutorial', 'size': '2105'}