- Seaborn 教程
- Seaborn - 首頁
- Seaborn - 簡介
- Seaborn - 環境配置
- 匯入資料集和庫
- Seaborn - 圖表美學
- Seaborn - 調色盤
- Seaborn - 直方圖
- Seaborn - 核密度估計
- 視覺化成對關係
- Seaborn - 繪製分類資料
- 觀測值的分佈
- Seaborn - 統計估計
- Seaborn - 繪製寬格式資料
- 多面板分類圖
- Seaborn - 線性關係
- Seaborn - Facet Grid (分面網格)
- Seaborn - Pair Grid (對網格)
- 函式參考
- Seaborn - 函式參考
- Seaborn 有用資源
- Seaborn - 快速指南
- Seaborn - 有用資源
- Seaborn - 討論
Seaborn.color_palette() 方法
Seaborn.color_palette() 方法返回由顏色列表或連續顏色對映定義的調色盤。
可以使用 seaborn color palette() 對繪圖進行著色,這將在後面演示。我們可以使用調色盤生成具有不同顏色的點。在下面的示例中,我們可以看到調色盤能夠生成各種顏色對映值。
語法
以下是 color_palette() 方法的語法:
seaborn.color_palette(palette=None, n_colors=None, desat=None, as_cmap=False)
引數
下面描述 seaborn.color_palette() 的引數。
| 序號 | 引數及描述 |
|---|---|
| 1 | Palette(調色盤) 要設定的調色盤。 |
| 2 | n_colors 迴圈中的顏色數量。 |
| 3 | Desat 每種顏色去飽和的比例。 |
| 4 | As_cmap 接受布林值,如果為 True,則返回 matplotlib 顏色對映。 |
返回值
由顏色列表或連續顏色對映定義的調色盤。
示例 1
在這個例子中,我們將看到如何在 seaborn 中使用color_palette() 方法。我們將把 matplotlib 調色盤作為引數傳遞給該方法,它將返回該調色盤中的一系列顏色。此方法可用於檢查特定調色盤中可用的顏色。稍後,可以使用 seaborn 中的 set_palette() 方法設定調色盤,並繪製圖表。
在這裡,我們將透過將其作為引數傳遞給 color_palette() 方法來檢視 flare 調色盤。
import seaborn as sns
import matplotlib.pyplot as plt
sns.palplot(sns.color_palette("flare"))
plt.show()
輸出
生成的輸出如下所示,其中包含 flare 調色盤中的所有顏色。
示例 2
在這個例子中,我們將連同調色盤名稱一起將一個整數值傳遞給color_palette() 方法,這個整數是n_colors值,它將顯示調色盤的這麼多顏色。
import seaborn as sns
import matplotlib.pyplot as plt
sns.palplot(sns.color_palette("flare", 20))
plt.show()
輸出
生成的輸出如下:
示例 3
在這個例子中,我們將使用 as_cmap 函式並將值 True 傳遞給它。可以使用下面的程式碼行來實現。
sns.color_palette("flare", as_cmap=True)
輸出
獲得的輸出如下:
seaborn_color_palettes_introduction.htm
廣告