Python seaborn heatmap中的定制调色板

Python seaborn heatmap中的定制调色板,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我使用以下命令绘制了以下相关矩阵“corr”: import seaborn as sns; sns.set() import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(6,6)) ax = sns.heatmap(corr, annot=True, fmt="0.2f", linewidths=.5) 是否有一种方法可以创建围绕0对称的调色板。绿色调在0左右,接近+1或-1时为红色调,如果可能的话

我使用以下命令绘制了以下相关矩阵“corr”:

import seaborn as sns; 
sns.set()
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6,6))
ax = sns.heatmap(corr, annot=True, fmt="0.2f", linewidths=.5)

是否有一种方法可以创建围绕0对称的调色板。绿色调在0左右,接近+1或-1时为红色调,如果可能的话。这样,绿色(或冷色)表示“无相关性”,红色(暖色)表示“高相关性”(正相关性或负相关性)

谢谢。

A可以使用。要使绿色正好位于中间,
vmin
vmax
需要将对称设置为零

导入seaborn作为sns;sns.set()
将matplotlib.pyplot作为plt导入
从matplotlib.colors导入LinearSegmentedColormap
将numpy作为np导入
corr=np.corrcoef(np.random.random((5,5)))
图,ax=plt.子批次(图尺寸=(6,6))
cmap=LinearSegmentedColormap。来自_列表('RedGreenRed',['crimson','lime','crimson'))
ax=sns.heatmap(corr,cmap=cmap,vmin=-1,vmax=1,annot=True,fmt=“0.2f”,线宽=0.5)
plt.show()

PS:在红色和绿色之间添加一个黄色可能会更好看:
LinearSegmentedColormap。从列表(“,['crimson','gold','Lame','gold','crimson'))