- Seaborn 教程
- Seaborn - 首頁
- Seaborn - 簡介
- Seaborn - 環境搭建
- 匯入資料集和庫
- Seaborn - 圖表美學
- Seaborn - 調色盤
- Seaborn - 直方圖
- Seaborn - 核密度估計
- 視覺化成對關係
- Seaborn - 繪製分類資料
- 觀測值的分佈
- Seaborn - 統計估計
- Seaborn - 繪製寬格式資料
- 多面板分類圖
- Seaborn - 線性關係
- Seaborn - Facet Grid
- Seaborn - Pair Grid
- 函式參考
- Seaborn - 函式參考
- Seaborn 有用資源
- Seaborn - 快速指南
- Seaborn - 有用資源
- Seaborn - 討論
Seaborn.diverging_palette() 方法
Seaborn.diverging_palette() 方法用於在兩種 HUSL 顏色之間建立發散圖。HUSL 顏色系統是 HSL 顏色系統的替代方案。目前稱為 HSLuv 系統。
choose_diverging_palette() 函式幫助我們藉助 IPython notebook 互動式地使用此方法。
語法
以下是 diverging_palette() 方法的語法:
seaborn.diverging_palette(h_neg, h_pos, s=75, l=50, sep=1, n=6, center='light', as_cmap=False)
引數
此方法的引數如下所示。
| 序號 | 引數和描述 |
|---|---|
| 1 | H_neg, h_pos 取 0 到 359 之間的浮點值,是對映負和正範圍的錨色相。 |
| 2 | S 取 0 到 100 之間的浮點值,是對映兩端的錨飽和度。 |
| 3 | L 取 0 到 100 之間的浮點值,是對映兩端的錨亮度。 |
| 4 | as_cmap 此可選引數取布林值,如果為真,則返回 matplotlib 顏色圖。 |
| 5 | sep 取整數值,是中間區域的大小。 |
| 6 | center 取 light 或 dark 作為值,並確定調色盤的中心是淺色還是深色。 |
| 7 | N 取整數值,如果未返回 cmap,則為調色盤中的顏色數量。 |
返回值
此方法返回 RGB 元組列表或 matplotlib 顏色圖。現在,我們將在以下示例中看到此方法的工作原理。
示例 1
在此示例中,我們將看到棕色到綠色的調色盤。為此,我們將傳遞 h_pos 和 h_neg 值,然後是 RGB 元組列表中要生成的顏色的數量。可以使用以下程式碼行。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.diverging_palette(200, 20, n=15))
plt.show()
輸出
輸出如下所示:
示例 2
在此示例中,我們將生成另一組與上述情況相同的顏色。在這種情況下,我們將生成藍色-粉色調色盤,但我們還將瞭解 sep 引數的用法,該引數確定中間區域的大小。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.diverging_palette(250, 349, n=15,sep=200))
plt.show()
輸出
輸出如下所示:
示例 3
我們將透過傳遞 h_pos、h_neg、亮度和飽和度引數以及生成的輸出中的顏色數量(在本例中為 15)來建立一箇中間帶有白色的藍色到紅色的調色盤。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.diverging_palette(250, 10, n=15,s=50,l=20))
plt.show()
輸出
輸出如下:
seaborn_color_palettes_introduction.htm
廣告