- Seaborn 教程
- Seaborn - 首頁
- Seaborn - 簡介
- Seaborn - 環境設定
- 匯入資料集和庫
- Seaborn - 圖表美學
- Seaborn - 顏色調色盤
- Seaborn - 直方圖
- Seaborn - 核密度估計
- 視覺化成對關係
- Seaborn - 繪製分類資料
- 觀測值的分佈
- Seaborn - 統計估計
- Seaborn - 繪製寬格式資料
- 多面板分類圖
- Seaborn - 線性關係
- Seaborn - Facet Grid
- Seaborn - Pair Grid
- 函式參考
- Seaborn - 函式參考
- Seaborn 有用資源
- Seaborn - 快速指南
- Seaborn - 有用資源
- Seaborn - 討論
Seaborn.mpl_palette() 方法
Seaborn.mpl_palette() 方法用於返回 matplotlib 調色盤的離散顏色值。
雖然如果你請求的顏色數量超過給定定性調色盤所能提供的數量,你將得到比預期更少的顏色,但此方法可以正確地管理定性顏色釀造調色盤。相反,使用 color palette() 請求定性顏色釀造調色盤將提供預期的顏色數量,但它們會迴圈。
對於連續調色盤,選擇均勻分佈的離散樣本(不包括顏色圖中的最小值和最大值)以提供更好的極端對比度。
語法
以下是 mpl_palette() 方法的語法:
seaborn.mpl_palette(name, n_colors=6, as_cmap=False)
引數
此方法的引數如下所示。
| 序號 | 引數和描述 |
|---|---|
| 1 | N_colors 取整數值,確定調色盤中離散顏色的數量。 |
| 2 | name 取字串值,是調色盤的名稱。此調色盤通常應為 matplotlib 顏色圖。 |
返回值
此方法返回 RGB 元組列表或 matplotlib 顏色圖。
示例 1
在這個例子中,我們將看到如何使用 mpl_palette 方法。我們將不得不使用 seaborn 中可用的 palplot 方法,使用此 mpl_palette 方法生成屬於特定調色盤的一系列顏色。此 mpl_palette() 方法返回一個 matplotlib 顏色圖。如果不需要,可以省略 palplot() 方法。
import seaborn as sns
import matplotlib.pyplot as plt
data = sns.palplot(sns.mpl_palette("gist_rainbow", 12))
sns.palplot(data)
plt.show()
輸出
獲得的輸出如下:
示例 2
我們將在此方法中看到其他調色盤。在這個例子中,我們將只使用 mpl_palette() 方法生成顏色圖,而不使用 palplot() 方法。
import seaborn as sns
import matplotlib.pyplot as plt
data = sns.mpl_palette("inferno", 12)
sns.palplot(data)
plt.show()
輸出
輸出如下:
示例 3
我們將看到此方法中可以使用所有調色盤的列表,以及我們將看到另一個調色盤及其包含的顏色。
'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'crest', 'crest_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'flare', 'flare_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'hot', 'hot_r', 'hsv', 'hsv_r', 'icefire', 'icefire_r', 'inferno', 'inferno_r', 'jet', 'jet_r'
上述名稱是 seaborn 顏色調色盤中的一部分顏色,所有這些內建的 seaborn 調色盤都可以用來根據我們的意願和需要生成顏色。另一個調色盤如下所示。
sns.mpl_palette("gist_earth", 12)
輸出
輸出如下:
seaborn_color_palettes_introduction.htm
廣告