Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为簇映射上等于零的值设置特定颜色_Python_Pandas_Matplotlib_Colors_Seaborn - Fatal编程技术网

Python 为簇映射上等于零的值设置特定颜色

Python 为簇映射上等于零的值设置特定颜色,python,pandas,matplotlib,colors,seaborn,Python,Pandas,Matplotlib,Colors,Seaborn,我想在seaborn集群地图的图形输出方面得到一些帮助 在我的数据中,我缺少转换为0的数据 我想有一个白色的值等于零,并为其余的值调色板 有没有办法在cmap中指出这一点 import pandas as pd from random import randint import seaborn as sns import matplotlib.pyplot as plt df = pd.DataFrame({'A': [randint(1, 10) for x in xrange(10)]+

我想在seaborn集群地图的图形输出方面得到一些帮助

在我的数据中,我缺少转换为0的数据

我想有一个白色的值等于零,并为其余的值调色板

有没有办法在cmap中指出这一点

import pandas as pd
from random import randint
import seaborn as sns
import matplotlib.pyplot as plt


df = pd.DataFrame({'A': [randint(1, 10) for x in xrange(10)]+[randint(30, 50) for x in xrange(5)]+[randint(70, 100) for x in xrange(5)],
         'B': [randint(0, 2) for x in xrange(10)]+[randint(30, 50) for x in xrange(5)]+[randint(70, 100) for x in xrange(5)],
         'C': [randint(0, 10) for x in xrange(10)]+[randint(30, 50) for x in xrange(5)]+[randint(60, 100) for x in xrange(5)],
         'D': [randint(0, 40) for x in xrange(10)]+[randint(30, 50) for x in xrange(5)]+[randint(60, 100) for x in xrange(5)]})

cmap = sns.cubehelix_palette(as_cmap=True, start=.5, rot=-.75, light=.9)

sns.clustermap(df, figsize=(13, 13), cmap=cmap)
实际群集:

值为0的结果为白色:
clustermap
具有kwarg
掩码
。从:

掩码:布尔数组或数据帧,可选

如果传递,数据将不会显示在掩码为True的单元格中。缺少值的单元格将自动屏蔽。仅用于可视化,不用于计算

因此,对于您的示例,可以使用布尔数组,如:
mask=(df==0)


上述解决方案对我不起作用,但将这些特定值(当等于零时)设置为NA起作用

是的,这就是我的建议。请注意,遮罩单元格显示轴的背景,因此,如果您希望将轴样式设置为具有白色背景(而非默认背景)的轴样式之一,则可以准确地获得所需的内容。
sns.clustermap(df, figsize=(13, 13), cmap=cmap, mask=(df==0))