xxxxxxxxxx
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# See heatmap
df_crosstab = pd.crosstab(df["cat_colx"], df["cat_coly"],
values=df["num_col"], aggfunc="mean")
sns.heatmap(df_crosstab, annot=True, fmt="d", cmap="YlGnBu",
cbar=False, linewidths=.5, center=df_crosstab.loc[9, 6])
# See heatmap of correlation
sns.heatmap(df.corr(), cmap='YlGnBu')
# Rotate tick marks for visibility
plt.yticks(rotation=0)
plt.xticks(rotation=90)
plt.show() #Show the plot
xxxxxxxxxx
# seaborn heatmap best parameter
plt.figure(figsize=(20,8))
sns.heatmap(corr, vmax=1, vmin=-1, center=0,
linewidth=.5,square=True, annot = True,
annot_kws = {'size':8},fmt='.1f', cmap='BrBG_r', ax=ax1, # ax: use this when using subplot
cbar_kws = dict(use_gridspec=False,location="top", shrink=0.9)) # cbar_kws: for positioning cbar and "shrink" for reducing cbar size
plt.title('Correlation')
plt.show()
xxxxxxxxxx
flights = sns.load_dataset("flights")
>>> flights = flights.pivot("month", "year", "passengers")
>>> ax = sns.heatmap(flights)