AS_*_*ler 1 python pandas seaborn
我正在使用seaborn 创建水平条形图。从这个例子来看,我是如何设置颜色的。
sns.set_color_codes("pastel")
sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b")
Run Code Online (Sandbox Code Playgroud)
因此,在此示例中,“总计”字段将具有来自“粉彩”调色板的颜色“b”(蓝色)。
我有大约 60 个不同的字段,并且我不想手动设置所有颜色。有没有办法让seaborn自动选择颜色(甚至调色板)?
就目前情况而言,我的计划是在一个周期中创建条形图
for field in fields:
sns.set_color_codes(foo)
sns.barplot(x=field, y="abbrev", data=crashes, label=field, color="bar")
Run Code Online (Sandbox Code Playgroud)
其中foo和bar是由seaborn以某种方式为我生成的。
您可以按照文档Seaborn Barplotpalette=中的指定使用 barplot 方法中的参数。
Seaborn Color Palette提供了一个非常好的示例,说明您可以向palette方法提供的值
my_palette = sns.color_palette("muted")
sns.barplot(x=field, y="abbrev", data=crashes, label=field, palette=my_palette)
Run Code Online (Sandbox Code Playgroud)