美文网首页
关于Seaborn中的corrplot和heatmap

关于Seaborn中的corrplot和heatmap

作者: SeekerLinJunYu | 来源:发表于2019-04-12 19:06 被阅读0次

corrplot已经被替换为heatmap,相关用法为:


效果图.png
from string import ascii_letters
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style="white")

# Generate a large random dataset
rs = np.random.RandomState(33)
d = pd.DataFrame(data=rs.normal(size=(100, 26)),
                 columns=list(ascii_letters[26:]))

# Compute the correlation matrix
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,
            square=True, linewidths=.5, cbar_kws={"shrink": .5})

相关文章

网友评论

      本文标题:关于Seaborn中的corrplot和heatmap

      本文链接:https://www.haomeiwen.com/subject/fqehwqtx.html