Seaborn FacetGrid lineplot: set specific line color in single subplot
在 Seaborn 中使用 FacetGrid 构建小倍数线图(或任何图表类型)时,您如何手动覆盖单个特定子图的线条颜色,以便例如突出显示某些内容并将其与其他子图进行对比?
在 Matplotlib 中,这是一项相对简单的任务,但我找不到一种方法来访问特定方面,然后自定义其中的样式,而其他所有方面均保持不变..
以下代码生成一个 2x2 图表,在所有子图中具有统一的样式:
1 2 3 4 | 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') |
....如果我的目标是增加线宽并更改第一个位置子图中的颜色,同时保持其他子图原样,我将如何实现?
您必须访问由
1 2 3 4 5 6 7 8 9 | 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') |
