热力图使用:sns.heatmap
,例子如下:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0, 5, size=(20, 5))) # 生成 df
# 开始绘图
f, ax = plt.subplots(figsize=(19, 16))
sns.heatmap(df.corr(), annot=True, linewidths=.5, ax=ax, cmap='RdBu_r', center=0)
plt.show()
cmap
:指定颜色