- Seaborn 教程
- Seaborn - 首頁
- Seaborn - 簡介
- Seaborn - 環境設定
- 匯入資料集和庫
- Seaborn - 圖表美學
- Seaborn - 顏色調色盤
- Seaborn - 直方圖
- Seaborn - 核密度估計
- 視覺化成對關係
- Seaborn - 繪製分類資料
- 觀測值的分佈
- Seaborn - 統計估計
- Seaborn - 繪製寬格式資料
- 多面板分類圖
- Seaborn - 線性關係
- Seaborn - FacetGrid
- Seaborn - PairGrid
- 函式參考
- Seaborn - 函式參考
- Seaborn 有用資源
- Seaborn - 快速指南
- Seaborn - 有用資源
- Seaborn - 討論
Seaborn.hls_palette() 方法
Seaborn.hls_palette() 方法用於獲取一組均勻分佈在HSL顏色空間中的顏色。
HSL系統包含用色相、飽和度和亮度測量的影像。色相代表影像的顏色,飽和度是顏色中純淨度的量,亮度是色相的強度。
這些色相通常均勻地分佈在圓形路徑上。因此,生成的調色盤將代表分類和迴圈資料。h、s和l的值必須始終在0和1之間。
語法
以下是hls_palette()方法的語法:
seaborn.hls_palette(n_colors=6, h=0.01, l=0.6, s=0.65, as_cmap=False)
引數
HLS調色盤方法的引數描述如下。
| 序號 | 引數和描述 |
|---|---|
| 1 | n_colors 迴圈中的顏色數量。 |
| 2 | h 接受浮點數,是顏色迴圈的第一個色相。 |
| 3 | s 接受浮點值,是顏色的飽和度。 |
| 4 | l 接受浮點值,是顏色的亮度。 |
返回值
它返回一個matplotlib顏色圖的RGB元組列表。
示例1
在這個例子中,我們將瞭解hls_palette()方法的工作原理。此方法基本上允許使用者透過更改顏色的色相、亮度和飽和度來建立自定義調色盤。
為了繪製自定義建立的調色盤,使用palplot()方法。這個seaborn.palplot()方法使使用者能夠繪製自定義調色盤並檢視特定調色盤中包含的潘通色。color_palette和palplto()方法的區別在於,color_palette()方法繪製matplotlib調色盤的顏色,而palplot()方法用於繪製自定義調色盤。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.hls_palette(15))
plt.show()
輸出
獲得的輸出如下:
示例2
在這個例子中,我們將色相值與n_colors值一起傳遞給hls_paletee()方法。這裡,色相值設定為0.4,這是自定義顏色系列中第一個色相的值。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.hls_palette(15,h=0.4))
plt.show()
輸出
獲得的輸出是以下顏色序列:
示例3
在這裡,我們將飽和度值與n-colors值一起傳遞給該方法。在本例中,飽和度設定為0.2。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
#sns.palplot(sns.hls_palette(16, s=.2))
plt.show()
輸出
產生的輸出如下:
示例4
在這裡,我們將亮度值與n_colors值一起傳遞給該方法。在本例中,亮度設定為0.5。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.hls_palette(11, l=.5))
plt.show()
輸出
產生的輸出如下:
示例5
在這裡,我們將所有引數傳遞給hls_palette()方法,然後繪製顏色。
import seaborn as sns
import matplotlib.pyplot as plt
titanic=sns.load_dataset("titanic")
titanic.head()
sns.palplot(sns.hls_palette(10, l=.7,s=.5,h=0.1))
plt.show()
輸出
產生的輸出如下: