所有盒子的相同颜色的Seaborn Boxplot

Chr*_*ris 3 python colors matplotlib boxplot seaborn

我正在使用seaborn并且想要生成一个盒子图,其中所有盒子都具有相同的颜色.出于某种原因,seaborn为每个盒子使用不同的颜色,并且没有选项来停止这种行为并为所有盒子设置相同的颜色.

我怎样才能强迫seaborn为所有盒子使用相同的颜色?

fig, ax = plt.subplots(figsize=(10, 20))
sns.boxplot(y='categorical_var', x='numeric_var', ax=ax)
Run Code Online (Sandbox Code Playgroud)

mwa*_*kom 5

使用color参数:

import seaborn as sns
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", data=tips, color="seagreen")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 请注意,您可以使用“color='C0'”以避免硬编码特定颜色。这将从 Matplotlib 的(可定制)颜色循环中获取第一种颜色。 (2认同)