Python Seaborn自动颜色选择
我正在使用seaborn创建一个水平条形图。下面是我如何设置颜色的示例Python Seaborn自动颜色选择,python,pandas,seaborn,Python,Pandas,Seaborn,我正在使用seaborn创建一个水平条形图。下面是我如何设置颜色的示例 sns.set_color_codes("pastel") sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b") 因此,在本例中,字段“total”将具有来自“粉彩”调色板的颜色“b”(表示蓝色) 我有大约60个不同的字段,我不想手动设置所有颜色。有没有办法让seaborn自动选择颜色(甚至调色板) 目前,我的计划是在一个周期内
sns.set_color_codes("pastel")
sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b")
因此,在本例中,字段“total”将具有来自“粉彩”调色板的颜色“b”(表示蓝色)
我有大约60个不同的字段,我不想手动设置所有颜色。有没有办法让seaborn自动选择颜色(甚至调色板)
目前,我的计划是在一个周期内创建条形图
for field in fields:
sns.set_color_codes(foo)
sns.barplot(x=field, y="abbrev", data=crashes, label=field, color="bar")
其中,seaborn以某种方式为我生成了
foo
和bar
。您可以在barplot方法中使用参数palette=
,如文档中所述
您可以提供给调色板
方法的一个非常好的值示例位于
您可以在barplot方法中使用参数
调色板=
,如文档中所述
您可以提供给调色板
方法的一个非常好的值示例位于
谢谢这与
my\u palete=sns.color\u palete(“Set1”,n\u colors=len(字段),desat=.5)
配合使用效果很好,然后设置palete=“Set1”
。太好了。仅供参考,不同的调色板也可以组合起来创建另一个,即您可以使用Set1和Set2中的一些颜色来创建自己的颜色。谢谢。这与my\u palete=sns.color\u palete(“Set1”,n\u colors=len(字段),desat=.5)
配合使用效果很好,然后设置palete=“Set1”
。太好了。仅供参考,不同的调色板也可以组合起来创建另一个调色板,即您可以使用Set1和Set2中的一些颜色创建自己的颜色。
my_palette = sns.color_palette("muted")
sns.barplot(x=field, y="abbrev", data=crashes, label=field, palette=my_palette)