Python 带seaborn clustermap的下三角遮罩

Python 带seaborn clustermap的下三角遮罩,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,在使用seaborn的clustermap进行分层聚类时,如何掩盖下三角 import numpy as np import seaborn as sns import matplotlib.pyplot as plt #pearson coefficients corr = np.corrcoef(np.random.randn(10, 200)) #lower triangle mask = np.tril(np.ones_like(corr)) fig, ax = plt.subplo

在使用seaborn的clustermap进行分层聚类时,如何掩盖下三角

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

#pearson coefficients
corr = np.corrcoef(np.random.randn(10, 200))

#lower triangle
mask = np.tril(np.ones_like(corr))
fig, ax = plt.subplots(figsize=(6,6))

#heatmap works as expected
sns.heatmap(corr, cmap="Blues", mask=mask, cbar=False)

#clustermap not so much
sns.clustermap(corr, cmap="Blues", mask=mask, figsize=(6,6))
plt.show()

嗯,
clustermap
根据相似性对值进行聚类。这将更改行和列的顺序

您可以创建常规clustermap,然后在第二步中应用遮罩:

将numpy导入为np
导入seaborn作为sns
将matplotlib.pyplot作为plt导入
corr=np.corrcoef(np.random.randn(10200))
g=sns.clustermap(corr,cmap=“Blues”,figsize=(6,6))
mask=np.tril(np.one_-like(corr))
values=g.ax\u heatmap.collections[0]。获取数组()。重塑形状(corr.shape)
新的_值=np.ma.array(值,掩码=掩码)
g、 ax\u热图。集合[0]。设置\u数组(新的\u值)
plt.show()