簡體   English   中英

Seaborn自動顏色選擇

[英]Seaborn automatic color selection

我正在使用seaborn來創建水平條形圖。 這個例子中,這里是我如何設置顏色。

sns.set_color_codes("pastel")
sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b")

因此,在此示例中,“總計”字段的顏色為“柔和”調色板中的顏色“ 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為我生成了foobar

您可以在文檔Seaborn Barplot中指定的barplot方法中使用參數palette=

您可以為palette方法提供的值的一個很好的例子是Seaborn調色板。

my_palette = sns.color_palette("muted")
sns.barplot(x=field, y="abbrev", data=crashes, label=field, palette=my_palette)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM