Seaborn FacetGrid lineplot:在单个子图中设置特定的线条颜色

Seaborn FacetGrid lineplot: set specific line color in single subplot

在 Seaborn 中使用 FacetGrid 构建小倍数线图图表(或任何图表类型)时,如何手动覆盖单个特定子图的线条颜色以便突出显示某些内容并将其与其他次要地块?

在 Matplotlib 中,这是一个相对简单的任务,但我找不到一种方法来访问特定的方面,然后在其中自定义样式,而其他所有方面都保持不变..

以下代码生成一个 2x2 图表,在所有子图中具有统一的样式:

tips = sns.load_dataset("tips")
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, row="sex", col="smoker", margin_titles=True)
g.map(sns.lineplot, "total_bill", 'tip')

...如果我的目标是增加线宽并更改第一个位置的子图中的颜色,同时保持其他子图不变,我将如何实现?

您将必须访问 FacetGrid 创建的轴之一,然后访问您要自定义的艺术家,并更改其属性。

tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, row="sex", col="smoker", margin_titles=True)
g.map(sns.lineplot, "total_bill", 'tip')

# customize first subplot
ax = g.facet_axis(0,0) # could also do ax=g.axes[0,0]
l = ax.get_lines()[0] # get the relevant Line2D object (in this case there is only one, but there could be more if using hues)
l.set_linewidth(3)
l.set_color('C1')