Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.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 覆盖对seaborn'的多个调用;具有不同色调分组的镶嵌面网格_Python_Seaborn - Fatal编程技术网

Python 覆盖对seaborn'的多个调用;具有不同色调分组的镶嵌面网格

Python 覆盖对seaborn'的多个调用;具有不同色调分组的镶嵌面网格,python,seaborn,Python,Seaborn,使用seaborn的FaceGrid,我想在多个映射调用之间更新“色调”分组参数。具体地说,我最初有一个自定义绘图函数,它采用“色调”分组,在此基础上我希望显示组间的平均值(因此忽略色调,并汇总所有数据) e、 g 将为每个组创建一条彩色回归线。如何更新FaceGrid以忽略第二次调用map时的hue分组?在本例中,我希望有两个彩色散点图,并覆盖一条(黑色)回归线。色调由FaceGrid用于对输入数据进行分组。它不能将其仅部分分组 matplotlib解决方案可能如下所示 import matp

使用seaborn的FaceGrid,我想在多个映射调用之间更新“色调”分组参数。具体地说,我最初有一个自定义绘图函数,它采用“色调”分组,在此基础上我希望显示组间的平均值(因此忽略色调,并汇总所有数据)

e、 g


将为每个组创建一条彩色回归线。如何更新FaceGrid以忽略第二次调用
map
时的
hue
分组?在本例中,我希望有两个彩色散点图,并覆盖一条(黑色)回归线。

色调由
FaceGrid
用于对输入数据进行分组。它不能将其仅部分分组

matplotlib解决方案可能如下所示

import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset("tips", cache=True)

n = len(tips["time"].unique())
usmoker = tips["smoker"].unique()

fig, axes = plt.subplots(ncols=n, sharex=True, sharey=True)

for ax, (time, grp1) in zip(axes.flat, tips.groupby("time")):
    ax.set_title(time)
    ax.set_prop_cycle(plt.rcParams["axes.prop_cycle"])

    for smoker in usmoker:
        grp2 = grp1[grp1["smoker"] == smoker]
        sns.regplot("total_bill", "tip", data=grp2, label=str(smoker), 
                    fit_reg=False, ax=ax)
    ax.legend(title="Smoker")  

for ax, (time, grp1) in zip(axes.flat, tips.groupby("time")):
    sns.regplot("total_bill", "tip", data=grp1, ax=ax, scatter=False, 
                color="k", label="regression line")


plt.show()

您可以在这里找到答案的要素:
import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset("tips", cache=True)

n = len(tips["time"].unique())
usmoker = tips["smoker"].unique()

fig, axes = plt.subplots(ncols=n, sharex=True, sharey=True)

for ax, (time, grp1) in zip(axes.flat, tips.groupby("time")):
    ax.set_title(time)
    ax.set_prop_cycle(plt.rcParams["axes.prop_cycle"])

    for smoker in usmoker:
        grp2 = grp1[grp1["smoker"] == smoker]
        sns.regplot("total_bill", "tip", data=grp2, label=str(smoker), 
                    fit_reg=False, ax=ax)
    ax.legend(title="Smoker")  

for ax, (time, grp1) in zip(axes.flat, tips.groupby("time")):
    sns.regplot("total_bill", "tip", data=grp1, ax=ax, scatter=False, 
                color="k", label="regression line")


plt.show()