Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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 3.x 嵌套行的Seaborn热图_Python 3.x_Pandas_Matplotlib_Seaborn - Fatal编程技术网

Python 3.x 嵌套行的Seaborn热图

Python 3.x 嵌套行的Seaborn热图,python-3.x,pandas,matplotlib,seaborn,Python 3.x,Pandas,Matplotlib,Seaborn,给定以下数据框和数据透视表: import pandas as pd df=pd.DataFrame({'A':['a','a','a','a','a','b','b','b','b'], 'B':['x','y','z','x','y','z','x','y','z'], 'C':['a','b','a','b','a','b','a','b','a'], 'D':[7,5,3,4,1,6,5

给定以下数据框和数据透视表:

import pandas as pd
df=pd.DataFrame({'A':['a','a','a','a','a','b','b','b','b'],
                 'B':['x','y','z','x','y','z','x','y','z'],
                 'C':['a','b','a','b','a','b','a','b','a'],
                 'D':[7,5,3,4,1,6,5,3,1]})
table = pd.pivot_table(df, index=['A', 'B','C'],aggfunc='sum')
table

            D
A   B   C   
a   x   a   7
        b   4
    y   a   1
        b   5
    z   a   3
b   x   a   5
    y   b   3
    z   a   1
        b   6
我想创建一个按索引a和B划分的热图,如下所示:

有可能吗?

您可以在
jupyter
笔记本中使用,请参阅和:


谢谢!您能告诉我如何将其导出为海生热图或类似于我的样本的更干净的东西吗?好的,您可以尝试打开Jupyter笔记本。对我来说,它在浏览器中打开新选项卡。然后你可以创建新的笔记本(右上角),并且可以下载为html、pdf、rst。。。
import seaborn as sns
import pandas as pd

df=pd.DataFrame({'A':['a','a','a','a','a','b','b','b','b'],
                 'B':['x','y','z','x','y','z','x','y','z'],
                 'C':['a','b','a','b','a','b','a','b','a'],
                 'D':[7,5,3,4,1,6,5,3,1]})
table = pd.pivot_table(df, index=['A', 'B','C'],aggfunc='sum')
table


cm = sns.light_palette("blue", as_cmap=True)
s = df.reset_index().style.background_gradient(cmap=cm)
s